package cn.wuxing.mediation.system.service.impl;

import cn.wuxing.mediation.common.utils.SecurityUtils;
import cn.wuxing.mediation.system.domain.LeadDutyArrangement;
import cn.wuxing.mediation.system.domain.ShiftScheduling;
import cn.wuxing.mediation.system.domain.vo.*;
import cn.wuxing.mediation.system.mapper.IndexDisputeEventMapper;
import cn.wuxing.mediation.system.service.ILeadDutyArrangementService;
import cn.wuxing.mediation.system.service.ISIndexService;
import cn.wuxing.mediation.system.service.IShiftSchedulingService;
import cn.wuxing.mediation.system.service.IVisitingReceptionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class ISIndexServiceImpl implements ISIndexService {

    @Resource
    private IndexDisputeEventMapper indexDisputeEventMapper;//纠纷

    @Resource
    private ILeadDutyArrangementService leadDutyArrangementService;//领导值班

    @Resource
    private IVisitingReceptionService visitingReceptionService;//考察接待

    @Resource
    private IShiftSchedulingService shiftSchedulingService;//庭室情况

    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
    private SimpleDateFormat simpleDateFormatYear = new SimpleDateFormat("yyyy");
    private SimpleDateFormat simpleDateFormatYMD = new SimpleDateFormat("yyyy-MM-dd");
    private static DecimalFormat f = new DecimalFormat("#0.0");

    /**
     * 获取权限
     *
     * @param userId
     * @return
     */
    //获取区级综窗权限
    private Long getRoleSynthesis(Long userId) {
        return indexDisputeEventMapper.getSynthesisRoleQujizongchuang(userId);
    }

    //获取乡镇综窗权限
    private Long getRoleSynthesisTown(Long userId) {
        return indexDisputeEventMapper.getSynthesisRoleXiangzhenzongchuang(userId);
    }


    /**
     * 纠纷总览
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<Object> disputeOverviewAll(String startTime, String endTime) {
        List<Object> dataResult = new ArrayList<>();
        Long userId = SecurityUtils.getUserId();//用户id
        if (userId == 1) {
            userId = null;
            dataResult.add(disputeOverviewByAdmin(startTime, endTime));
            dataResult.add(disputeTypeOverviewByAdmin(startTime, endTime));
            dataResult.add(disputeTypeAreaOverviewByAdmin(startTime, endTime));
            return dataResult;
        }
        //1、区级综窗
        Long roleSynthesis = getRoleSynthesis(userId);
        if (roleSynthesis != null) {
            dataResult.add(disputeOverviewSynthesis(userId, startTime, endTime));
            dataResult.add(disputeTypeOverviewBySynthesis(userId, startTime, endTime));
            dataResult.add(disputeTypeAreaOverviewBySynthesis(userId, startTime, endTime));
        }
        //2、乡镇综窗
        Long roleSynthesisTown = getRoleSynthesisTown(userId);
        if (roleSynthesisTown != null) {//乡镇综窗
            dataResult.add(disputeOverviewSynthesis(userId, startTime, endTime));
            dataResult.add(disputeTypeOverviewBySynthesis(userId, startTime, endTime));
            dataResult.add(disputeTypeAreaOverviewBySynthesis(userId, startTime, endTime));
            return dataResult;
        }
        //3、专窗
        Long[] windowIds = indexDisputeEventMapper.getWindowIdByUserId(userId);
        if (windowIds!=null&&windowIds.length>0) {
            dataResult.add(disputeOverviewWindows(windowIds, startTime, endTime));
            dataResult.add(disputeTypeOverviewByWindows(windowIds, startTime, endTime));
            dataResult.add(disputeTypeAreaOverviewByWindows(windowIds, startTime, endTime));
            return dataResult;
        }
        //4、乡镇治理中心
        Long[] townShipIds = indexDisputeEventMapper.getTownShipByUserId(userId);
        if (townShipIds!=null&&townShipIds.length>0) {
            dataResult.add(disputeOverviewTownShip(townShipIds, startTime, endTime));
            dataResult.add(disputeTypeOverviewByTownShip(townShipIds, startTime, endTime));
            dataResult.add(disputeTypeAreaOverviewByTownShip(townShipIds, startTime, endTime));
            return dataResult;
        }
        //4、调解员
        dataResult.add(disputeOverviewMediator(userId, startTime, endTime));
        dataResult.add(disputeTypeOverviewByMediator(userId, startTime, endTime));
        dataResult.add(disputeTypeAreaOverviewByMediator(userId, startTime, endTime));
        return dataResult;
    }

    //超管
    private List<Object> disputeTypeAreaOverviewByAdmin(String startTime, String endTime) {
        //TODO
//        List<Map<String, Object>> areaList = getAreaTown();
        //非纠纷
        List<Map<String, Object>> disputeAreaNot = indexDisputeEventMapper.getDisputeAreaNot(startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> disputeAreaOrd = indexDisputeEventMapper.getDisputeAreaOrd(startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> disputeAreaPre = indexDisputeEventMapper.getDisputeAreaPre(startTime, endTime);

        List<Map<String, Object>> notNotNull = disputeAreaNot.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> ordNotNull = disputeAreaOrd.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> preNotNull = disputeAreaPre.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        Long preId = null;
        if (notNotNull.size() > 0) {
            preId = (Long) notNotNull.get(0).get("areaType");
        }
        if (ordNotNull.size() > 0) {
            preId = (Long) ordNotNull.get(0).get("areaType");
        }
        if (preNotNull.size() > 0) {
            preId = (Long) preNotNull.get(0).get("areaType");
        }
        List<Map<String, Object>> areaVillage = getAreaVillage(preId);
        List<Object> dataResult = new ArrayList();
        for (Map<String, Object> area : areaVillage) {
            Map<String, Object> objectMap = new HashMap<>();
            List<Object> dataList = new ArrayList<>();
            List<Map<String, Object>> notList = notNotNull.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> ordList = ordNotNull.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> preList = preNotNull.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            //组合数据
            dataList.addAll(notList);
            dataList.addAll(ordList);
            dataList.addAll(preList);
            objectMap.put("data", dataList);
            objectMap.put("area", area);
            dataResult.add(objectMap);
        }
        if (dataResult.size() == 0) {
            dataResult = getDefaultValueArea();
        }
        return dataResult;
    }

    private List<Map<String, Object>> disputeTypeOverviewByAdmin(String startTime, String endTime) {
        List<Map<String, Object>> data = new ArrayList<>();
        //非纠纷类型
        List<Map<String, Object>> notType = indexDisputeEventMapper.getNotDisputeTypeByAdmin(startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> ordinaryType = indexDisputeEventMapper.getOrdinaryTypeByAdmin(startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> preType = indexDisputeEventMapper.getPreTypeByAdmin(startTime, endTime);

        data.addAll(notType);
        data.addAll(ordinaryType);
        data.addAll(preType);
        if (data.size() == 0) {
            data = getDefaultValue();
        }
        return data;
    }

    private Map<String, Long> disputeOverviewByAdmin(String startTime, String endTime) {
        //非纠纷
        Map<String, Long> notAll = indexDisputeEventMapper.getNotDisputeAllByAdmin(startTime, endTime);
        //一般纠纷
        Map<String, Long> ordinaryAll = indexDisputeEventMapper.getOrdinaryAllByAdmin(startTime, endTime);
        //诉前调解件
        Map<String, Long> preAll = indexDisputeEventMapper.getPreAllByAdmin(startTime, endTime);
        HashMap<String, Long> map = new HashMap<>();
        map.put("notCount", notAll.get("total"));
        map.put("ordinaryCount", ordinaryAll.get("total"));
        map.put("preCount", preAll.get("total"));
        //accepted1 待受理
        map.put("accepted1", notAll.get("accepted1") + ordinaryAll.get("accepted1") + preAll.get("accepted1"));
        //accepted2 已受理
        map.put("accepted2", notAll.get("accepted2") + ordinaryAll.get("accepted2") + preAll.get("accepted2"));
        //mediated1 待调解
        map.put("mediated1", ordinaryAll.get("mediated1") + preAll.get("mediated1"));
        //mediated2 已调解
        map.put("mediated2", ordinaryAll.get("mediated2") + preAll.get("mediated2"));
        return map;
    }

    //综窗
    private Map<String, Long> disputeOverviewSynthesis(Long userId, String startTime, String endTime) {
        //非纠纷
        Map<String, Long> notAll = indexDisputeEventMapper.getNotDisputeAllBySynthesis(userId, startTime, endTime);
        //一般纠纷
        Map<String, Long> ordinaryAll = indexDisputeEventMapper.getOrdinaryAllBySynthesis(userId, startTime, endTime);
        //诉前调解件
        Map<String, Long> preAll = indexDisputeEventMapper.getPreAllBySynthesis(userId, startTime, endTime);
        HashMap<String, Long> map = new HashMap<>();
        map.put("notCount", notAll.get("total"));
        map.put("ordinaryCount", ordinaryAll.get("total"));
        map.put("preCount", preAll.get("total"));
        //accepted1 待受理
        map.put("accepted1", notAll.get("accepted1") + ordinaryAll.get("accepted1") + preAll.get("accepted1"));
        //accepted2 已受理
        map.put("accepted2", notAll.get("accepted2") + ordinaryAll.get("accepted2") + preAll.get("accepted2"));
        //mediated1 待调解
        map.put("mediated1", ordinaryAll.get("mediated1") + preAll.get("mediated1"));
        //mediated2 已调解
        map.put("mediated2", ordinaryAll.get("mediated2") + preAll.get("mediated2"));
        return map;
    }

    private List<Map<String, Object>> disputeTypeOverviewBySynthesis(Long userId, String startTime, String endTime) {
        List<Map<String, Object>> data = new ArrayList<>();
        //非纠纷类型
        List<Map<String, Object>> notType = indexDisputeEventMapper.getNotDisputeTypeBySynthesis(userId, startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> ordinaryType = indexDisputeEventMapper.getOrdinaryTypeBySynthesis(userId, startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> preType = indexDisputeEventMapper.getPreTypeBySynthesis(userId, startTime, endTime);

        data.addAll(notType);
        data.addAll(ordinaryType);
        data.addAll(preType);
        if (data.size() == 0) {
            data = getDefaultValue();
        }
        return data;
    }

    private List<Object> disputeTypeAreaOverviewBySynthesis(Long userId, String startTime, String endTime) {
        //TODO
//        List<Map<String, Object>> areaList = getAreaTown();
        //非纠纷
        List<Map<String, Object>> disputeAreaNot = indexDisputeEventMapper.getDisputeAreaNotSynthesis(userId, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> disputeAreaOrd = indexDisputeEventMapper.getDisputeAreaOrdSynthesis(userId, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> disputeAreaPre = indexDisputeEventMapper.getDisputeAreaPreSynthesis(userId, startTime, endTime);

        List<Map<String, Object>> notNotNull = disputeAreaNot.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> ordNotNull = disputeAreaOrd.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> preNotNull = disputeAreaPre.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        Long preId = null;
        if (notNotNull.size() > 0) {
            preId = (Long) notNotNull.get(0).get("areaType");
        }
        if (ordNotNull.size() > 0) {
            preId = (Long) ordNotNull.get(0).get("areaType");
        }
        if (preNotNull.size() > 0) {
            preId = (Long) preNotNull.get(0).get("areaType");
        }
        List<Map<String, Object>> areaVillage = getAreaVillage(preId);

        List<Object> dataResult = new ArrayList();
        for (Map<String, Object> area : areaVillage) {
            Map<String, Object> objectMap = new HashMap<>();
            List<Object> dataList = new ArrayList<>();
            List<Map<String, Object>> notList = notNotNull.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> ordList = ordNotNull.stream()
                    .filter(map -> map.get("areaType").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> preList = preNotNull.stream()
                    .filter(map -> map.get("areaType").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            //组合数据
            dataList.addAll(notList);
            dataList.addAll(ordList);
            dataList.addAll(preList);
            objectMap.put("data", dataList);
            objectMap.put("area", area);
            dataResult.add(objectMap);
        }
        if (dataResult.size() == 0) {
            dataResult = getDefaultValueArea();
        }
        return dataResult;
    }

    //专窗
    private Map<String, Long> disputeOverviewWindows(Long[] windows, String startTime, String endTime) {
        //非纠纷
        Map<String, Long> notAll = indexDisputeEventMapper.getNotDisputeAllByWindows(windows, startTime, endTime);
        //一般纠纷
        Map<String, Long> ordinaryAll = indexDisputeEventMapper.getOrdinaryAllByWindows(windows, startTime, endTime);
        //诉前调解件
        Map<String, Long> preAll = indexDisputeEventMapper.getPreAllByWindows(windows, startTime, endTime);
        HashMap<String, Long> map = new HashMap<>();
        map.put("notCount", notAll.get("total"));
        map.put("ordinaryCount", ordinaryAll.get("total"));
        map.put("preCount", preAll.get("total"));
        //accepted1 待受理
        map.put("accepted1", notAll.get("accepted1") + ordinaryAll.get("accepted1") + preAll.get("accepted1"));
        //accepted2 已受理
        map.put("accepted2", notAll.get("accepted2") + ordinaryAll.get("accepted2") + preAll.get("accepted2"));
        //mediated1 待调解
        map.put("mediated1", ordinaryAll.get("mediated1") + preAll.get("mediated1"));
        //mediated2 已调解
        map.put("mediated2", ordinaryAll.get("mediated2") + preAll.get("mediated2"));
        return map;
    }

    private List<Map<String, Object>> disputeTypeOverviewByWindows(Long[] windows, String startTime, String endTime) {
        List<Map<String, Object>> data = new ArrayList<>();
        //非纠纷类型
        List<Map<String, Object>> notType = indexDisputeEventMapper.getNotDisputeTypeByWindows(windows, startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> ordinaryType = indexDisputeEventMapper.getOrdinaryTypeByWindows(windows, startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> preType = indexDisputeEventMapper.getPreTypeByWindows(windows, startTime, endTime);

        data.addAll(notType);
        data.addAll(ordinaryType);
        data.addAll(preType);
        if (data.size() == 0) {
            data = getDefaultValue();
        }
        return data;
    }

    private List<Object> disputeTypeAreaOverviewByWindows(Long[] windows, String startTime, String endTime) {
        //TODO
//        List<Map<String, Object>> areaList = getAreaTown();
        //非纠纷
        List<Map<String, Object>> disputeAreaNot = indexDisputeEventMapper.getDisputeAreaNotWindows(windows, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> disputeAreaOrd = indexDisputeEventMapper.getDisputeAreaOrdWindows(windows, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> disputeAreaPre = indexDisputeEventMapper.getDisputeAreaPreWindows(windows, startTime, endTime);

        List<Map<String, Object>> notNotNull = disputeAreaNot.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> ordNotNull = disputeAreaOrd.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> preNotNull = disputeAreaPre.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        Long preId = null;
        if (notNotNull.size() > 0) {
            preId = (Long) notNotNull.get(0).get("areaType");
        }
        if (ordNotNull.size() > 0) {
            preId = (Long) ordNotNull.get(0).get("areaType");
        }
        if (preNotNull.size() > 0) {
            preId = (Long) preNotNull.get(0).get("areaType");
        }
        List<Map<String, Object>> areaVillage = getAreaVillage(preId);

        List<Object> dataResult = new ArrayList();
        for (Map<String, Object> area : areaVillage) {
            Map<String, Object> objectMap = new HashMap<>();
            List<Object> dataList = new ArrayList<>();
            List<Map<String, Object>> notList = notNotNull.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> ordList = ordNotNull.stream()
                    .filter(map -> map.get("areaType").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> preList = preNotNull.stream()
                    .filter(map -> map.get("areaType").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            //组合数据
            dataList.addAll(notList);
            dataList.addAll(ordList);
            dataList.addAll(preList);
            objectMap.put("data", dataList);
            objectMap.put("area", area);
            dataResult.add(objectMap);
        }
        if (dataResult.size() == 0) {
            dataResult = getDefaultValueArea();
        }
        return dataResult;
    }

    //治理中心
    private Map<String, Long> disputeOverviewTownShip(Long[] townShipIds, String startTime, String endTime) {
        //非纠纷
        Map<String, Long> notAll = indexDisputeEventMapper.getNotDisputeAllByTownShip(townShipIds, startTime, endTime);
        //一般纠纷
        Map<String, Long> ordinaryAll = indexDisputeEventMapper.getOrdinaryAllByTownShip(townShipIds, startTime, endTime);
        //诉前调解件
        Map<String, Long> preAll = indexDisputeEventMapper.getPreAllByTownShip(townShipIds, startTime, endTime);
        HashMap<String, Long> map = new HashMap<>();
        map.put("notCount", notAll.get("total"));
        map.put("ordinaryCount", ordinaryAll.get("total"));
        map.put("preCount", preAll.get("total"));
        //accepted1 待受理
        map.put("accepted1", notAll.get("accepted1") + ordinaryAll.get("accepted1") + preAll.get("accepted1"));
        //accepted2 已受理
        map.put("accepted2", notAll.get("accepted2") + ordinaryAll.get("accepted2") + preAll.get("accepted2"));
        //mediated1 待调解
        map.put("mediated1", ordinaryAll.get("mediated1") + preAll.get("mediated1"));
        //mediated2 已调解
        map.put("mediated2", ordinaryAll.get("mediated2") + preAll.get("mediated2"));
        return map;
    }

    private List<Map<String, Object>> disputeTypeOverviewByTownShip(Long[] townShipIds, String startTime, String endTime) {
        List<Map<String, Object>> data = new ArrayList<>();
        //非纠纷类型
        List<Map<String, Object>> notType = indexDisputeEventMapper.getNotDisputeTypeByTownShip(townShipIds, startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> ordinaryType = indexDisputeEventMapper.getOrdinaryTypeByTownShip(townShipIds, startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> preType = indexDisputeEventMapper.getPreTypeByTownShip(townShipIds, startTime, endTime);

        data.addAll(notType);
        data.addAll(ordinaryType);
        data.addAll(preType);
        if (data.size() == 0) {
            data = getDefaultValue();
        }
        return data;
    }

    private List<Object> disputeTypeAreaOverviewByTownShip(Long[] townShipIds, String startTime, String endTime) {
        //TODO
//        List<Map<String, Object>> areaList = getAreaTown();
        //非纠纷
        List<Map<String, Object>> disputeAreaNot = indexDisputeEventMapper.getDisputeAreaNotTownShip(townShipIds, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> disputeAreaOrd = indexDisputeEventMapper.getDisputeAreaOrdTownShip(townShipIds, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> disputeAreaPre = indexDisputeEventMapper.getDisputeAreaPreTownShip(townShipIds, startTime, endTime);

        List<Map<String, Object>> notNotNull = disputeAreaNot.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> ordNotNull = disputeAreaOrd.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> preNotNull = disputeAreaPre.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        Long preId = null;
        if (notNotNull.size() > 0) {
            preId = (Long) notNotNull.get(0).get("areaType");
        }
        if (ordNotNull.size() > 0) {
            preId = (Long) ordNotNull.get(0).get("areaType");
        }
        if (preNotNull.size() > 0) {
            preId = (Long) preNotNull.get(0).get("areaType");
        }
        List<Map<String, Object>> areaVillage = getAreaVillage(preId);

        List<Object> dataResult = new ArrayList();
        for (Map<String, Object> area : areaVillage) {
            Map<String, Object> objectMap = new HashMap<>();
            List<Object> dataList = new ArrayList<>();
            List<Map<String, Object>> notList = notNotNull.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> ordList = ordNotNull.stream()
                    .filter(map -> map.get("areaType").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> preList = preNotNull.stream()
                    .filter(map -> map.get("areaType").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            //组合数据
            dataList.addAll(notList);
            dataList.addAll(ordList);
            dataList.addAll(preList);
            objectMap.put("data", dataList);
            objectMap.put("area", area);
            dataResult.add(objectMap);
        }
        if (dataResult.size() == 0) {
            dataResult = getDefaultValueArea();
        }
        return dataResult;
    }

    //调解员
    private Map<String, Long> disputeOverviewMediator(Long userId, String startTime, String endTime) {
        //非纠纷
        Map<String, Long> notAll = indexDisputeEventMapper.getNotDisputeAllByMediator(userId, startTime, endTime);
        //一般纠纷
        Map<String, Long> ordinaryAll = indexDisputeEventMapper.getOrdinaryAllByMediator(userId, startTime, endTime);
        //诉前调解件
        Map<String, Long> preAll = indexDisputeEventMapper.getPreAllByMediator(userId, startTime, endTime);
        HashMap<String, Long> map = new HashMap<>();
        map.put("notCount", notAll.get("total"));
        map.put("ordinaryCount", ordinaryAll.get("total"));
        map.put("preCount", preAll.get("total"));
        //accepted1 待受理
        map.put("accepted1", notAll.get("accepted1") + ordinaryAll.get("accepted1") + preAll.get("accepted1"));
        //accepted2 已受理
        map.put("accepted2", notAll.get("accepted2") + ordinaryAll.get("accepted2") + preAll.get("accepted2"));
        //mediated1 待调解
        map.put("mediated1", ordinaryAll.get("mediated1") + preAll.get("mediated1"));
        //mediated2 已调解
        map.put("mediated2", ordinaryAll.get("mediated2") + preAll.get("mediated2"));
        return map;
    }

    private List<Map<String, Object>> disputeTypeOverviewByMediator(Long userId, String startTime, String endTime) {
        List<Map<String, Object>> data = new ArrayList<>();
        //非纠纷类型
        List<Map<String, Object>> notType = indexDisputeEventMapper.getNotDisputeTypeByMediator(userId, startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> ordinaryType = indexDisputeEventMapper.getOrdinaryTypeByMediator(userId, startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> preType = indexDisputeEventMapper.getPreTypeByMediator(userId, startTime, endTime);

        data.addAll(notType);
        data.addAll(ordinaryType);
        data.addAll(preType);
        if (data.size() == 0) {
            data = getDefaultValue();
        }
        return data;
    }

    private List<Object> disputeTypeAreaOverviewByMediator(Long userId, String startTime, String endTime) {
        //TODO
//        List<Map<String, Object>> areaList = getAreaTown();
        //非纠纷
        List<Map<String, Object>> disputeAreaNot = indexDisputeEventMapper.getDisputeAreaNotMediator(userId, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> disputeAreaOrd = indexDisputeEventMapper.getDisputeAreaOrdMediator(userId, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> disputeAreaPre = indexDisputeEventMapper.getDisputeAreaPreMediator(userId, startTime, endTime);

        List<Map<String, Object>> notNotNull = disputeAreaNot.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> ordNotNull = disputeAreaOrd.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> preNotNull = disputeAreaPre.stream()
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        Long preId = null;
        if (notNotNull.size() > 0) {
            preId = (Long) notNotNull.get(0).get("areaType");
        }
        if (ordNotNull.size() > 0) {
            preId = (Long) ordNotNull.get(0).get("areaType");
        }
        if (preNotNull.size() > 0) {
            preId = (Long) preNotNull.get(0).get("areaType");
        }
        List<Map<String, Object>> areaVillage = getAreaVillage(preId);

        List<Object> dataResult = new ArrayList();
        for (Map<String, Object> area : areaVillage) {
            Map<String, Object> objectMap = new HashMap<>();
            List<Object> dataList = new ArrayList<>();
            List<Map<String, Object>> notList = notNotNull.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> ordList = ordNotNull.stream()
                    .filter(map -> map.get("areaType").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> preList = preNotNull.stream()
                    .filter(map -> map.get("areaType").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            //组合数据
            dataList.addAll(notList);
            dataList.addAll(ordList);
            dataList.addAll(preList);
            objectMap.put("data", dataList);
            objectMap.put("area", area);
            dataResult.add(objectMap);
        }
        if (dataResult.size() == 0) {
            dataResult = getDefaultValueArea();
        }
        return dataResult;
    }

    //大屏纠纷类型统计引用
    public List<Map<String, Object>> disputeTypeOverview1(String startTime, String endTime) {
        List<Map<String, Object>> data = new ArrayList<>();
        //非纠纷类型
        List<Map<String, Object>> notType = indexDisputeEventMapper.getNotDisputeType(startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> ordinaryType = indexDisputeEventMapper.getOrdinaryType(startTime, endTime);
        //一般纠纷类型
        List<Map<String, Object>> preType = indexDisputeEventMapper.getPreType(startTime, endTime);

        data.addAll(notType);
        data.addAll(ordinaryType);
        data.addAll(preType);
        return data;
    }

    @Override
    public List<Object> getDisputeRegistration(String query) {
        List<Object> resultData = new ArrayList<>();
        QueryTimeVo time = getTime(query);
        //非纠纷
        List<Map<String, Object>> registrationNot = indexDisputeEventMapper
                .getDisputeRegistrationNot(time.getStartTime(), time.getEndTime());
        //一般纠纷
        List<Map<String, Object>> registrationOrd = indexDisputeEventMapper
                .getDisputeRegistrationOrd(time.getStartTime(), time.getEndTime());
        //诉前纠纷
        List<Map<String, Object>> registrationPre = indexDisputeEventMapper
                .getDisputeRegistrationPre(time.getStartTime(), time.getEndTime());
        double percentage = 0.0;//百分比
        long notCountAll = 0;//总数
        long ordCountAll = 0;//总数
        long preCountAll = 0;//总数
        for (Map<String, Object> notMap : registrationNot) {
            Long count = (Long) notMap.get("count");
            if (count != null) {
                notCountAll += count;
            }
        }
        for (Map<String, Object> notMap : registrationNot) {
            Long count = (Long) notMap.get("count");
            if (count != 0 || notCountAll != 0) {
                percentage = ((count * 1.0) / notCountAll) * 100;
            } else {
                percentage = 0.0;
            }
            String resultPercentage = f.format(percentage);
            notMap.put("percentage", resultPercentage + "%");
            notMap.put("total", notCountAll);
        }

        for (Map<String, Object> ordMap : registrationOrd) {
            Long count = (Long) ordMap.get("count");
            if (count != null) {
                ordCountAll += count;
            }
        }
        for (Map<String, Object> ordMap : registrationOrd) {
            Long count = (Long) ordMap.get("count");
            if (count != 0 || ordCountAll != 0) {
                percentage = ((count * 1.0) / ordCountAll) * 100;
            } else {
                percentage = 0.0;
            }
            String resultPercentage = f.format(percentage);
            ordMap.put("percentage", resultPercentage + "%");
            ordMap.put("total", ordCountAll);
        }

        for (Map<String, Object> preMap : registrationPre) {
            Long count = (Long) preMap.get("count");
            if (count != null) {
                preCountAll += count;
            }
        }
        for (Map<String, Object> preMap : registrationPre) {
            Long count = (Long) preMap.get("count");
            if (count != 0 || preCountAll != 0) {
                percentage = ((count * 1.0) / preCountAll) * 100;
            } else {
                percentage = 0.0;
            }
            String resultPercentage = f.format(percentage);
            preMap.put("percentage", resultPercentage + "%");
            preMap.put("total", preCountAll);
        }

        if(registrationNot.size()==0){
            registrationNot=getDefaultValueNotReception();
        }
        if(registrationOrd.size()==0){
            registrationOrd=getDefaultValueOrdReception();
        }
        if(registrationPre.size()==0){
            registrationPre=getDefaultValuePreReception();
        }
        resultData.add(registrationNot);
        resultData.add(registrationOrd);
        resultData.add(registrationPre);
        return resultData;
    }

    @Override
    public List<Object> getDataCount() {
        List<Object> resultData = new ArrayList<>();
        Map<String, Object> leadMap = new HashMap<>();
        Map<String, Object> shitMap = new HashMap<>();

        QueryTimeVo leadTimeVo = getTime("YEAR");
        //领导值班
        LeadDutyArrangement leadDutyArrangement = new LeadDutyArrangement();
        leadDutyArrangement.setStartTime(leadTimeVo.getStartTime());
        leadDutyArrangement.setEndTime(leadTimeVo.getEndTime());
        List<LeadDutyArrangement> leadDutyArrangements = leadDutyArrangementService
                .selectLeadDutyArrangementList(leadDutyArrangement);
        //庭室情况
        QueryTimeVo shiftScheduleTime = getTime("DAY");
        Date date = new Date();
        int month = date.getMonth() + 1;
        int day = date.getDate();
        ShiftScheduling shiftScheduling = new ShiftScheduling();
        shiftScheduling.setStartTime(shiftScheduleTime.getStartTime());
        shiftScheduling.setEndTime(shiftScheduleTime.getEndTime());
//        List<ShiftScheduling> shiftSchedulings = shiftSchedulingService
//                .selectShiftSchedulingList(new ShiftScheduling());
        List<ShiftScheduling> shiftSchedulings = shiftSchedulingService
                .selectShiftSchedulings(new ShiftScheduling());
        //当日数据统计
        Map<String, Long> notCount = indexDisputeEventMapper
                .getDisputeDayNotCount(shiftScheduleTime.getStartTime(), shiftScheduleTime.getEndTime());
        Map<String, Long> ordCount = indexDisputeEventMapper
                .getDisputeDayOrdCount(shiftScheduleTime.getStartTime(), shiftScheduleTime.getEndTime());
        Map<String, Long> preCount = indexDisputeEventMapper
                .getDisputeDayPreCount(shiftScheduleTime.getStartTime(), shiftScheduleTime.getEndTime());
        //累计
        Map<String, Long> notCountAll = indexDisputeEventMapper
                .getDisputeDayNotCount(null, null);
        Map<String, Long> ordCountALl = indexDisputeEventMapper
                .getDisputeDayOrdCount(null, null);
        Map<String, Long> preCountAll = indexDisputeEventMapper
                .getDisputeDayPreCount(null, null);
        //考察调研累计
        Map<String, Long> visitingReceptionCount = visitingReceptionService.selectVisitingReceptionCount();
        String people = String.valueOf(visitingReceptionCount.get("people"));
        if (people == null || people.equals("null")) {
            visitingReceptionCount.put("people", 0l);
        }
        //组合数据
        leadMap.put("label", simpleDateFormatYear.format(date) + "年部门领导矛调中心大厅值班安排");
        leadMap.put("data", leadDutyArrangements);

        shitMap.put("label", "庭室情况(" + month + "月" + day + "日)");
        shitMap.put("data", shiftSchedulings);


        Map<String, Object> dataCount = new HashMap<>();
        Map<String, Object> dataMapDay = new HashMap<>();
        Map<String, Object> dataMapAll = new HashMap<>();
        dataMapDay.put("batchDay", ordCount.get("disputeCount")
                + notCount.get("disputeCount")
                + preCount.get("disputeCount"));//当日批次
        String people1 = String.valueOf(notCount.get("people"));
        if (people1 == null || people1.equals("null")) {
            notCount.put("people", 0l);
        }
        String people2 = String.valueOf(ordCount.get("people"));
        if (people2 == null || people2.equals("null")) {
            ordCount.put("people", 0l);
        }
        String people3 = String.valueOf(preCount.get("people"));
        if (people3 == null || people3.equals("null")) {
            preCount.put("people", 0l);
        }

        String people4 = String.valueOf(notCountAll.get("people"));
        if (people4 == null || people4.equals("null")) {
            notCountAll.put("people", 0l);
        }
        String people5 = String.valueOf(ordCountALl.get("people"));
        if (people5 == null || people5.equals("null")) {
            ordCountALl.put("people", 0l);
        }
        String people6 = String.valueOf(preCountAll.get("people"));
        if (people6 == null || people6.equals("null")) {
            preCountAll.put("people", 0l);
        }

        dataMapDay.put("peopleCount", Long.parseLong(String.valueOf(notCount.get("people")))
                + Long.parseLong(String.valueOf(ordCount.get("people")))
                + Long.parseLong(String.valueOf(preCount.get("people"))));//当日来访人数

        dataMapAll.put("batchDay", notCountAll.get("disputeCount")
                + ordCountALl.get("disputeCount")
                + preCountAll.get("disputeCount"));//累计批次
        dataMapAll.put("peopleCount", Long.parseLong(String.valueOf(notCountAll.get("people")))
                + Long.parseLong(String.valueOf(ordCountALl.get("people")))
                + Long.parseLong(String.valueOf(preCountAll.get("people"))));//累计来访人数

        dataCount.put("dataDay", dataMapDay);
        dataCount.put("dataAll", dataMapAll);
        dataCount.put("reception", visitingReceptionCount);

        resultData.add(leadMap);
        resultData.add(shitMap);
        resultData.add(dataCount);
        return resultData;
    }

    @Override
    public List<Object> disputeDeleteList(DisputeDeleteQueryVo disputeDeleteQueryVo) {
        String category = disputeDeleteQueryVo.getCategory();
        List<Object> result = new ArrayList<>();
        switch (category) {
            case "2"://一般纠纷
                List<DisputeOrdVo> ordVos = indexDisputeEventMapper.getDisputeDeleteListOrd(disputeDeleteQueryVo);
                result.addAll(ordVos);
                break;
            case "3":
                List<DisputePreVo> preVos = indexDisputeEventMapper.getDisputeDeleteListPre(disputeDeleteQueryVo);
                result.addAll(preVos);
                break;
        }
        return result;
    }

    @Override
    public int disputeRestore(DisputeDeleteQueryVo disputeDeleteQueryVo) {
        String category = disputeDeleteQueryVo.getCategory();
        int result = -1;
        if(disputeDeleteQueryVo.getIds()==null){
            return result;
        }
        if(disputeDeleteQueryVo.getIds().length==0){
            return result;
        }
        switch (category) {
            case "2":
                result = indexDisputeEventMapper.disputeRestoreOrd(disputeDeleteQueryVo);
                break;
            case "3":
                result = indexDisputeEventMapper.disputeRestorePre(disputeDeleteQueryVo);
                break;
        }
        return result;
    }

    @Override
    public List<QuickEntryVo> quickEntryAll() {
        List<QuickEntryVo> dataResult = new ArrayList<>();
        Long userId = SecurityUtils.getUserId();//用户id
        String role = "";
        if (userId == 1) {//超管
            List<QuickEntryVo> quickEntryAll = indexDisputeEventMapper.getQuickEntryAll(role);
            dataResult.addAll(quickEntryAll);
            return dataResult;
        }
        Long roleQujizongchuang = indexDisputeEventMapper.getSynthesisRoleQujizongchuang(userId);
        if (roleQujizongchuang != null) {//区级综窗
            role = "1";
            List<QuickEntryVo> quickEntryAll = indexDisputeEventMapper.getQuickEntryAll(role);
            dataResult.addAll(quickEntryAll);
        }
        Long roleXiangzhenzongchuang = indexDisputeEventMapper.getSynthesisRoleXiangzhenzongchuang(userId);
        if (roleXiangzhenzongchuang != null) {//乡镇综窗
            role = "1";
            List<QuickEntryVo> quickEntryAll = indexDisputeEventMapper.getQuickEntryAll(role);
            dataResult.addAll(quickEntryAll);
        }
        Long roleQujizhuanchuang = indexDisputeEventMapper.getWindowRoleQujizhuanchuang(userId);
        if (roleQujizhuanchuang != null) {//区级专窗
            role = "2";
            List<QuickEntryVo> quickEntryAll = indexDisputeEventMapper.getQuickEntryAll(role);
            dataResult.addAll(quickEntryAll);
        }
        Long roleZhilizhongxin = indexDisputeEventMapper.getWindowRoleZhilizhongxin(userId);
        if (roleZhilizhongxin != null) {//乡镇治理中心
            role = "2";
            List<QuickEntryVo> quickEntryAll = indexDisputeEventMapper.getQuickEntryAll(role);
            dataResult.addAll(quickEntryAll);
        }
        Long roleQujitiaojieyuan = indexDisputeEventMapper.getMediatorRoleQujitiaojieyuan(userId);
        if (roleQujitiaojieyuan != null) {//区级调解员
            role = "3";
            List<QuickEntryVo> quickEntryAll = indexDisputeEventMapper.getQuickEntryAll(role);
            dataResult.addAll(quickEntryAll);
        }
        Long roleXiangzhentiaojieyuan = indexDisputeEventMapper.getMediatorRoleXiangzhentiaojieyuan(userId);
        if (roleXiangzhentiaojieyuan != null) {//乡镇调解员
            role = "3";
            List<QuickEntryVo> quickEntryAll = indexDisputeEventMapper.getQuickEntryAll(role);
            dataResult.addAll(quickEntryAll);
        }
        return dataResult;
    }

    @Override
    public List<QuickEntryVo> quickEntry() {
        List<QuickEntryVo> quickEntryVos=new ArrayList<>();
        Long userId = SecurityUtils.getUserId();//用户id
        String str=indexDisputeEventMapper.getQuickEntry(userId);
        if(str!=null){
           if(str.equals("")){
               return quickEntryVos;
           }
            String[] split = str.split(",");
            List<Long> quickEntryIds=new ArrayList<>();
            if(split.length>0){
                for (int i = 0; i < split.length; i++) {
                    quickEntryIds.add(Long.valueOf(split[i]));
                }
            }
            if(quickEntryIds.size()>0){
                quickEntryVos.addAll(indexDisputeEventMapper.getQuickEntryById(quickEntryIds));
            }
        }
        return quickEntryVos;
    }

    @Override
    public Integer quickEntrySave(Long[] ids) {
        Integer result=0;
        Long userId = SecurityUtils.getUserId();//用户id
        if(ids!=null&&ids.length>0){
            String s="";
            for (int i = 0; i < ids.length; i++) {
                s+=ids[i]+",";
            }
            result=indexDisputeEventMapper.getQuickEntrySave(userId,s);
        }else {
            result=indexDisputeEventMapper.getQuickEntrySave(userId,"");
        }
        return result;
    }

    @Override
    public List<Map<String, Object>> getAreaVillageAll() {
        return indexDisputeEventMapper.getVillageAll();
    }

    @Override
    public List<Map<String, Object>> getAreaGridAll() {
        return indexDisputeEventMapper.getAreaGridAll();
    }

    @Override
    public Map<String, Object> getAreaByName(String areaName) {
        return indexDisputeEventMapper.getAreaByName(areaName);
    }

    @Override
    public Map<String, Object> disputeSubjectDistribution(String startTime, String endTime) {
        if (startTime == null) {
            startTime = "";
        }
        if (endTime == null) {
            endTime = "";
        }
        Map<String, Object> dataResult = null;
        Long userId = SecurityUtils.getUserId();//用户id
        if (userId == 1) {
            dataResult = getSubjectByAdmin(startTime, endTime);
            return dataResult;
        }
        //1、区级综窗
        Long roleSynthesis = getRoleSynthesis(userId);
        if (roleSynthesis != null) {
            dataResult = getSubjectBySynthesis(userId, startTime, endTime);
            return dataResult;
        }
        //2、乡镇综窗
        Long roleSynthesisTown = getRoleSynthesisTown(userId);
        if (roleSynthesisTown != null) {//乡镇综窗
            dataResult = getSubjectBySynthesis(userId, startTime, endTime);
            return dataResult;
        }
        //3、专窗
        Long[] windowIds = indexDisputeEventMapper.getWindowIdByUserId(userId);
        if (windowIds!=null&&windowIds.length > 0) {
            dataResult = getSubjectByWindows(windowIds, startTime, endTime);
            return dataResult;
        }
        //4、治理中心
        Long[] townShipByUserId = indexDisputeEventMapper.getTownShipByUserId(userId);
        if (townShipByUserId!=null&&townShipByUserId.length > 0) {
            dataResult = getSubjectByTownShip(townShipByUserId, startTime, endTime);
            return dataResult;
        }
        //5、调解员
        dataResult = getSubjectByMediator(userId, startTime, endTime);
        return dataResult;
    }

    //超管
    public Map<String, Object> getSubjectByAdmin(String startTime, String endTime) {
        Map<String, Object> dataResult = new HashMap<>();
        //申请类别 1、申请人 2、被申请人
        //申请人类型 1、自然人 2、法人组织 3、非法人组织
        List<Map<String, Object>> applicantSubject = indexDisputeEventMapper.getApplicantSubject(startTime, endTime);
        //申请人数据
        List<Map<String, Object>> applicant = applicantSubject.stream()
                .filter(map -> (int) map.get("category") == 1)
                .collect(Collectors.toList());
        //被申请人
        List<Map<String, Object>> respondent = applicantSubject.stream()
                .filter(map -> (int) map.get("category") == 2)
                .collect(Collectors.toList());

        Long naturalPersonTotal = 0l;
        Long legalEntitiesTotal = 0l;
        Long unincorporatedOrganizationsTotal = 0l;
        for (int i = 0; i < 3; i++) {
            if (applicant.size() > i) {
                Map<String, Object> map1 = applicant.get(i);
                String applicant1 = map1.get("applicant").toString();

                map1.put("label", getDisputeLabel(applicant1));
                if (applicant1.equals("1")) {
                    naturalPersonTotal += (Long) map1.get("count");
                } else if (applicant1.equals("2")) {
                    legalEntitiesTotal += (Long) map1.get("count");
                } else if (applicant1.equals("3")) {
                    unincorporatedOrganizationsTotal += (Long) map1.get("count");
                }
            }

            if (respondent.size() > i) {
                Map<String, Object> map2 = respondent.get(i);
                String applicant2 = map2.get("applicant").toString();
                map2.put("label", getDisputeLabel(applicant2));
                if (applicant2.equals("1")) {
                    naturalPersonTotal += (Long) map2.get("count");
                } else if (applicant2.equals("2")) {
                    legalEntitiesTotal += (Long) map2.get("count");
                } else if (applicant2.equals("3")) {
                    unincorporatedOrganizationsTotal += (Long) map2.get("count");
                }
            }

        }
        Map<String, Object> d1 = new HashMap<>();
        d1.put("label", getDisputeLabel("1"));
        d1.put("count", naturalPersonTotal);

        Map<String, Object> d2 = new HashMap<>();
        d2.put("label", getDisputeLabel("2"));
        d2.put("count", legalEntitiesTotal);

        Map<String, Object> d3 = new HashMap<>();
        d3.put("label", getDisputeLabel("3"));
        d3.put("count", unincorporatedOrganizationsTotal);
        List<Map<String, Object>> dataAll = new ArrayList<>();
        dataAll.add(d1);
        dataAll.add(d2);
        dataAll.add(d3);

        if (applicant.size() == 0) {
            applicant = getDefaultValuePeople();
        } else {
            if (applicant.size() == 1) {
                if (applicant.get(0).get("applicant").equals("1")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "法人组织");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("2")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
            }
            if (applicant.size() == 2) {
                if (applicant.get(0).get("applicant").equals("1") && applicant.get(1).get("applicant").equals("2")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("1") && applicant.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("2") && applicant.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                }
            }
        }
        if (respondent.size() == 0) {
            respondent = getDefaultValuePeople();
        } else {
            if (respondent.size() == 1) {
                if (respondent.get(0).get("applicant").equals("1")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "法人组织");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("2")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
            }
            if (respondent.size() == 2) {
                if (respondent.get(0).get("applicant").equals("1") && respondent.get(1).get("applicant").equals("2")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("1") && respondent.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("2") && respondent.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                }
            }
        }
        if (dataAll.size() == 0) {
            dataAll = getDefaultValuePeople();
        }
        dataResult.put("applicant", applicant);
        dataResult.put("respondent", respondent);
        dataResult.put("all", dataAll);
        return dataResult;
    }

    //区级综窗
    private Map<String, Object> getSubjectBySynthesis(Long userId, String startTime, String endTime) {
        Map<String, Object> dataResult = new HashMap<>();
        //申请类别 1、申请人 2、被申请人
        //申请人类型 1、自然人 2、法人组织 3、非法人组织
        List<Map<String, Object>> applicantSubject = indexDisputeEventMapper.getApplicantSubjectSynthesis(userId, startTime, endTime);
        List<Map<String, Object>> applicantSubjectOrd = indexDisputeEventMapper.getApplicantSubjectSynthesisOrd(userId, startTime, endTime);
        List<Map<String, Object>> applicantSubjectPre = indexDisputeEventMapper.getApplicantSubjectSynthesisPre(userId, startTime, endTime);
        List<Map<String, Object>> all = new ArrayList<>();

        all.addAll(applicantSubject);
        all.addAll(applicantSubjectOrd);
        all.addAll(applicantSubjectPre);
        //申请人数据
        List<Map<String, Object>> applicant = all.stream()
                .filter(map -> (int) map.get("category") == 1)
                .collect(Collectors.toList());
        //被申请人
        List<Map<String, Object>> respondent = all.stream()
                .filter(map -> (int) map.get("category") == 2)
                .collect(Collectors.toList());

        Long naturalPersonTotal = 0l;
        Long legalEntitiesTotal = 0l;
        Long unincorporatedOrganizationsTotal = 0l;

        long count = 0;
        int category = 0;
        String appName = "";

        if (applicant.size() > 0) {
            appName = String.valueOf(applicant.get(0).get("applicant"));
            category = (int) applicant.get(0).get("category");
            for (Map<String, Object> app : applicant) {
                count += (Long) app.get("count");
            }
            Map<String, Object> app = new HashMap<>();
            app.put("applicant", appName);
            app.put("count", count);
            app.put("category", category);
            applicant = new ArrayList<>();
            applicant.add(app);
        }
        if (respondent.size() > 0) {
            count = 0;
            category = (int) respondent.get(0).get("category");
            appName = String.valueOf(respondent.get(0).get("applicant"));
            for (Map<String, Object> resp : respondent) {
                count += (Long) resp.get("count");
            }
            Map<String, Object> resp = new HashMap<>();
            resp.put("applicant", appName);
            resp.put("count", count);
            resp.put("category", category);
            respondent = new ArrayList<>();
            respondent.add(resp);
        }

        for (int i = 0; i < 3; i++) {
            if (applicant.size() > i) {
                Map<String, Object> map1 = applicant.get(i);
                String applicant1 = map1.get("applicant").toString();
                map1.put("label", getDisputeLabel(applicant1));
                if (applicant1.equals("1")) {
                    naturalPersonTotal += (Long) map1.get("count");
                } else if (applicant1.equals("2")) {
                    legalEntitiesTotal += (Long) map1.get("count");
                } else if (applicant1.equals("3")) {
                    unincorporatedOrganizationsTotal += (Long) map1.get("count");
                }
            }

            if (respondent.size() > i) {
                Map<String, Object> map2 = respondent.get(i);
                String applicant2 = map2.get("applicant").toString();
                map2.put("label", getDisputeLabel(applicant2));
                if (applicant2.equals("1")) {
                    naturalPersonTotal += (Long) map2.get("count");
                } else if (applicant2.equals("2")) {
                    legalEntitiesTotal += (Long) map2.get("count");
                } else if (applicant2.equals("3")) {
                    unincorporatedOrganizationsTotal += (Long) map2.get("count");
                }
            }
        }
        Map<String, Object> d1 = new HashMap<>();
        d1.put("label", getDisputeLabel("1"));
        d1.put("count", naturalPersonTotal);

        Map<String, Object> d2 = new HashMap<>();
        d2.put("label", getDisputeLabel("2"));
        d2.put("count", legalEntitiesTotal);

        Map<String, Object> d3 = new HashMap<>();
        d3.put("label", getDisputeLabel("3"));
        d3.put("count", unincorporatedOrganizationsTotal);
        List<Map<String, Object>> dataAll = new ArrayList<>();
        dataAll.add(d1);
        dataAll.add(d2);
        dataAll.add(d3);
        if (applicant.size() == 0) {
            applicant = getDefaultValuePeople();
        } else {
            if (applicant.size() == 1) {
                if (applicant.get(0).get("applicant").equals("1")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "法人组织");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("2")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
            }
            if (applicant.size() == 2) {
                if (applicant.get(0).get("applicant").equals("1") && applicant.get(1).get("applicant").equals("2")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("1") && applicant.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("2") && applicant.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                }
            }
        }
        if (respondent.size() == 0) {
            respondent = getDefaultValuePeople();
        } else {
            if (respondent.size() == 1) {
                if (respondent.get(0).get("applicant").equals("1")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "法人组织");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("2")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
            }
            if (respondent.size() == 2) {
                if (respondent.get(0).get("applicant").equals("1") && respondent.get(1).get("applicant").equals("2")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("1") && respondent.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("2") && respondent.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                }
            }
        }
        if (dataAll.size() == 0) {
            dataAll = getDefaultValuePeople();
        }
        dataResult.put("applicant", applicant);
        dataResult.put("respondent", respondent);
        dataResult.put("all", dataAll);
        return dataResult;
    }

    //专窗
    private Map<String, Object> getSubjectByWindows(Long[] windows, String startTime, String endTime) {
        Map<String, Object> dataResult = new HashMap<>();
        //申请类别 1、申请人 2、被申请人
        //申请人类型 1、自然人 2、法人组织 3、非法人组织
        if (windows.length == 0) {
            windows = new Long[]{Long.valueOf(999999999)};
        }
        List<Map<String, Object>> applicantSubject = indexDisputeEventMapper.getApplicantSubjectWindows(windows, startTime, endTime);
        List<Map<String, Object>> applicantSubjectOrd = indexDisputeEventMapper.getApplicantSubjectWindowsOrd(windows, startTime, endTime);
        List<Map<String, Object>> applicantSubjectPre = indexDisputeEventMapper.getApplicantSubjectWindowsPre(windows, startTime, endTime);

        List<Map<String, Object>> all = new ArrayList<>();
        all.addAll(applicantSubject);
        all.addAll(applicantSubjectOrd);
        all.addAll(applicantSubjectPre);
        //申请人数据
        List<Map<String, Object>> applicant = all.stream()
                .filter(map -> (int) map.get("category") == 1)
                .collect(Collectors.toList());
        //被申请人
        List<Map<String, Object>> respondent = all.stream()
                .filter(map -> (int) map.get("category") == 2)
                .collect(Collectors.toList());

        long count = 0;
        int category = 0;
        String appName = "";

        if (applicant.size() > 0) {
            appName = String.valueOf(applicant.get(0).get("applicant"));
            category = (int) applicant.get(0).get("category");
            for (Map<String, Object> app : applicant) {
                count += (Long) app.get("count");
            }
            Map<String, Object> app = new HashMap<>();
            app.put("applicant", appName);
            app.put("count", count);
            app.put("category", category);
            applicant = new ArrayList<>();
            applicant.add(app);
        }
        if (respondent.size() > 0) {
            count = 0;
            category = (int) respondent.get(0).get("category");
            appName = String.valueOf(respondent.get(0).get("applicant"));
            for (Map<String, Object> resp : respondent) {
                count += (Long) resp.get("count");
            }
            Map<String, Object> resp = new HashMap<>();
            resp.put("applicant", appName);
            resp.put("count", count);
            resp.put("category", category);
            respondent = new ArrayList<>();
            respondent.add(resp);
        }

        Long naturalPersonTotal = 0l;
        Long legalEntitiesTotal = 0l;
        Long unincorporatedOrganizationsTotal = 0l;
        for (int i = 0; i < 3; i++) {
            if (applicant.size() > i) {
                Map<String, Object> map1 = applicant.get(i);
                String applicant1 = map1.get("applicant").toString();
                map1.put("label", getDisputeLabel(applicant1));
                if (applicant1.equals("1")) {
                    naturalPersonTotal += (Long) map1.get("count");
                } else if (applicant1.equals("2")) {
                    legalEntitiesTotal += (Long) map1.get("count");
                } else if (applicant1.equals("3")) {
                    unincorporatedOrganizationsTotal += (Long) map1.get("count");
                }
            }

            if (respondent.size() > i) {
                Map<String, Object> map2 = respondent.get(i);
                String applicant2 = map2.get("applicant").toString();
                map2.put("label", getDisputeLabel(applicant2));
                if (applicant2.equals("1")) {
                    naturalPersonTotal += (Long) map2.get("count");
                } else if (applicant2.equals("2")) {
                    legalEntitiesTotal += (Long) map2.get("count");
                } else if (applicant2.equals("3")) {
                    unincorporatedOrganizationsTotal += (Long) map2.get("count");
                }
            }

        }
        Map<String, Object> d1 = new HashMap<>();
        d1.put("label", getDisputeLabel("1"));
        d1.put("count", naturalPersonTotal);

        Map<String, Object> d2 = new HashMap<>();
        d2.put("label", getDisputeLabel("2"));
        d2.put("count", legalEntitiesTotal);

        Map<String, Object> d3 = new HashMap<>();
        d3.put("label", getDisputeLabel("3"));
        d3.put("count", unincorporatedOrganizationsTotal);
        List<Map<String, Object>> dataAll = new ArrayList<>();
        dataAll.add(d1);
        dataAll.add(d2);
        dataAll.add(d3);
        if (applicant.size() == 0) {
            applicant = getDefaultValuePeople();
        } else {
            if (applicant.size() == 1) {
                if (applicant.get(0).get("applicant").equals("1")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "法人组织");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("2")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
            }
            if (applicant.size() == 2) {
                if (applicant.get(0).get("applicant").equals("1") && applicant.get(1).get("applicant").equals("2")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("1") && applicant.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("2") && applicant.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                }
            }
        }
        if (respondent.size() == 0) {
            respondent = getDefaultValuePeople();
        } else {
            if (respondent.size() == 1) {
                if (respondent.get(0).get("applicant").equals("1")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "法人组织");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("2")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
            }
            if (respondent.size() == 2) {
                if (respondent.get(0).get("applicant").equals("1") && respondent.get(1).get("applicant").equals("2")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("1") && respondent.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("2") && respondent.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                }
            }
        }
        if (dataAll.size() == 0) {
            dataAll = getDefaultValuePeople();
        }
        dataResult.put("applicant", applicant);
        dataResult.put("respondent", respondent);
        dataResult.put("all", dataAll);
        return dataResult;
    }

    //治理中心
    private Map<String, Object> getSubjectByTownShip(Long[] townShipIds, String startTime, String endTime) {
        Map<String, Object> dataResult = new HashMap<>();
        //申请类别 1、申请人 2、被申请人
        //申请人类型 1、自然人 2、法人组织 3、非法人组织
        if (townShipIds.length == 0) {
            townShipIds = new Long[]{Long.valueOf(999999999)};
        }
        List<Map<String, Object>> applicantSubject = indexDisputeEventMapper.getApplicantSubjectTownShip(townShipIds, startTime, endTime);
        List<Map<String, Object>> applicantSubjectOrd = indexDisputeEventMapper.getApplicantSubjectTownShipOrd(townShipIds, startTime, endTime);
        List<Map<String, Object>> applicantSubjectPre = indexDisputeEventMapper.getApplicantSubjectTownShipPre(townShipIds, startTime, endTime);

        List<Map<String, Object>> all = new ArrayList<>();
        all.addAll(applicantSubject);
        all.addAll(applicantSubjectOrd);
        all.addAll(applicantSubjectPre);
        //申请人数据
        List<Map<String, Object>> applicant = all.stream()
                .filter(map -> (int) map.get("category") == 1)
                .collect(Collectors.toList());
        //被申请人
        List<Map<String, Object>> respondent = all.stream()
                .filter(map -> (int) map.get("category") == 2)
                .collect(Collectors.toList());

        long count = 0;
        int category = 0;
        String appName = "";

        if (applicant.size() > 0) {
            appName = String.valueOf(applicant.get(0).get("applicant"));
            category = (int) applicant.get(0).get("category");
            for (Map<String, Object> app : applicant) {
                count += (Long) app.get("count");
            }
            Map<String, Object> app = new HashMap<>();
            app.put("applicant", appName);
            app.put("count", count);
            app.put("category", category);
            applicant = new ArrayList<>();
            applicant.add(app);
        }
        if (respondent.size() > 0) {
            count = 0;
            category = (int) respondent.get(0).get("category");
            appName = String.valueOf(respondent.get(0).get("applicant"));
            for (Map<String, Object> resp : respondent) {
                count += (Long) resp.get("count");
            }
            Map<String, Object> resp = new HashMap<>();
            resp.put("applicant", appName);
            resp.put("count", count);
            resp.put("category", category);
            respondent = new ArrayList<>();
            respondent.add(resp);
        }

        Long naturalPersonTotal = 0l;
        Long legalEntitiesTotal = 0l;
        Long unincorporatedOrganizationsTotal = 0l;
        for (int i = 0; i < 3; i++) {
            if (applicant.size() > i) {
                Map<String, Object> map1 = applicant.get(i);
                String applicant1 = map1.get("applicant").toString();
                map1.put("label", getDisputeLabel(applicant1));
                if (applicant1.equals("1")) {
                    naturalPersonTotal += (Long) map1.get("count");
                } else if (applicant1.equals("2")) {
                    legalEntitiesTotal += (Long) map1.get("count");
                } else if (applicant1.equals("3")) {
                    unincorporatedOrganizationsTotal += (Long) map1.get("count");
                }
            }

            if (respondent.size() > i) {
                Map<String, Object> map2 = respondent.get(i);
                String applicant2 = map2.get("applicant").toString();
                map2.put("label", getDisputeLabel(applicant2));
                if (applicant2.equals("1")) {
                    naturalPersonTotal += (Long) map2.get("count");
                } else if (applicant2.equals("2")) {
                    legalEntitiesTotal += (Long) map2.get("count");
                } else if (applicant2.equals("3")) {
                    unincorporatedOrganizationsTotal += (Long) map2.get("count");
                }
            }

        }
        Map<String, Object> d1 = new HashMap<>();
        d1.put("label", getDisputeLabel("1"));
        d1.put("count", naturalPersonTotal);

        Map<String, Object> d2 = new HashMap<>();
        d2.put("label", getDisputeLabel("2"));
        d2.put("count", legalEntitiesTotal);

        Map<String, Object> d3 = new HashMap<>();
        d3.put("label", getDisputeLabel("3"));
        d3.put("count", unincorporatedOrganizationsTotal);
        List<Map<String, Object>> dataAll = new ArrayList<>();
        dataAll.add(d1);
        dataAll.add(d2);
        dataAll.add(d3);
        if (applicant.size() == 0) {
            applicant = getDefaultValuePeople();
        } else {
            if (applicant.size() == 1) {
                if (applicant.get(0).get("applicant").equals("1")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "法人组织");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("2")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
            }
            if (applicant.size() == 2) {
                if (applicant.get(0).get("applicant").equals("1") && applicant.get(1).get("applicant").equals("2")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("1") && applicant.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("2") && applicant.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                }
            }
        }
        if (respondent.size() == 0) {
            respondent = getDefaultValuePeople();
        } else {
            if (respondent.size() == 1) {
                if (respondent.get(0).get("applicant").equals("1")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "法人组织");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("2")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
            }
            if (respondent.size() == 2) {
                if (respondent.get(0).get("applicant").equals("1") && respondent.get(1).get("applicant").equals("2")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("1") && respondent.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("2") && respondent.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                }
            }
        }
        if (dataAll.size() == 0) {
            dataAll = getDefaultValuePeople();
        }
        dataResult.put("applicant", applicant);
        dataResult.put("respondent", respondent);
        dataResult.put("all", dataAll);
        return dataResult;
    }

    //调解员
    private Map<String, Object> getSubjectByMediator(Long userId, String startTime, String endTime) {
        Map<String, Object> dataResult = new HashMap<>();
        //申请类别 1、申请人 2、被申请人
        //申请人类型 1、自然人 2、法人组织 3、非法人组织
        List<Map<String, Object>> applicantSubject = indexDisputeEventMapper.getApplicantSubjectMediator(userId, startTime, endTime);
        List<Map<String, Object>> applicantSubjectOrd = indexDisputeEventMapper.getApplicantSubjectMediatorOrd(userId, startTime, endTime);
        List<Map<String, Object>> applicantSubjectPre = indexDisputeEventMapper.getApplicantSubjectMediatorPre(userId, startTime, endTime);
        List<Map<String, Object>> all = new ArrayList<>();
        all.addAll(applicantSubject);
        all.addAll(applicantSubjectOrd);
        all.addAll(applicantSubjectPre);
        //申请人数据
        List<Map<String, Object>> applicant = all.stream()
                .filter(map -> (int) map.get("category") == 1)
                .collect(Collectors.toList());
        //被申请人
        List<Map<String, Object>> respondent = all.stream()
                .filter(map -> (int) map.get("category") == 2)
                .collect(Collectors.toList());

        long count = 0;
        int category = 0;
        String appName = "";

        if (applicant.size() > 0) {
            appName = String.valueOf(applicant.get(0).get("applicant"));
            category = (int) applicant.get(0).get("category");
            for (Map<String, Object> app : applicant) {
                count += (Long) app.get("count");
            }
            Map<String, Object> app = new HashMap<>();
            app.put("applicant", appName);
            app.put("count", count);
            app.put("category", category);
            applicant = new ArrayList<>();
            applicant.add(app);
        }
        if (respondent.size() > 0) {
            count = 0;
            category = (int) respondent.get(0).get("category");
            appName = String.valueOf(respondent.get(0).get("applicant"));
            for (Map<String, Object> resp : respondent) {
                count += (Long) resp.get("count");
            }
            Map<String, Object> resp = new HashMap<>();
            resp.put("applicant", appName);
            resp.put("count", count);
            resp.put("category", category);
            respondent = new ArrayList<>();
            respondent.add(resp);
        }

        Long naturalPersonTotal = 0l;
        Long legalEntitiesTotal = 0l;
        Long unincorporatedOrganizationsTotal = 0l;
        for (int i = 0; i < 3; i++) {
            if (applicant.size() > i) {
                Map<String, Object> map1 = applicant.get(i);
                String applicant1 = map1.get("applicant").toString();
                map1.put("label", getDisputeLabel(applicant1));
                if (applicant1.equals("1")) {
                    naturalPersonTotal += (Long) map1.get("count");
                } else if (applicant1.equals("2")) {
                    legalEntitiesTotal += (Long) map1.get("count");
                } else if (applicant1.equals("3")) {
                    unincorporatedOrganizationsTotal += (Long) map1.get("count");
                }
            }

            if (respondent.size() > i) {
                Map<String, Object> map2 = respondent.get(i);
                String applicant2 = map2.get("applicant").toString();
                map2.put("label", getDisputeLabel(applicant2));
                if (applicant2.equals("1")) {
                    naturalPersonTotal += (Long) map2.get("count");
                } else if (applicant2.equals("2")) {
                    legalEntitiesTotal += (Long) map2.get("count");
                } else if (applicant2.equals("3")) {
                    unincorporatedOrganizationsTotal += (Long) map2.get("count");
                }
            }

        }
        Map<String, Object> d1 = new HashMap<>();
        d1.put("label", getDisputeLabel("1"));
        d1.put("count", naturalPersonTotal);

        Map<String, Object> d2 = new HashMap<>();
        d2.put("label", getDisputeLabel("2"));
        d2.put("count", legalEntitiesTotal);

        Map<String, Object> d3 = new HashMap<>();
        d3.put("label", getDisputeLabel("3"));
        d3.put("count", unincorporatedOrganizationsTotal);
        List<Map<String, Object>> dataAll = new ArrayList<>();
        dataAll.add(d1);
        dataAll.add(d2);
        dataAll.add(d3);
        if (applicant.size() == 0) {
            applicant = getDefaultValuePeople();
        } else {
            if (applicant.size() == 1) {
                if (applicant.get(0).get("applicant").equals("1")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "法人组织");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("2")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
            }
            if (applicant.size() == 2) {
                if (applicant.get(0).get("applicant").equals("1") && applicant.get(1).get("applicant").equals("2")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("1") && applicant.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    applicant.add(map1);
                }
                if (applicant.get(0).get("applicant").equals("2") && applicant.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    applicant.add(map);
                }
            }
        }
        if (respondent.size() == 0) {
            respondent = getDefaultValuePeople();
        } else {
            if (respondent.size() == 1) {
                if (respondent.get(0).get("applicant").equals("1")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "法人组织");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("2")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
            }
            if (respondent.size() == 2) {
                if (respondent.get(0).get("applicant").equals("1") && respondent.get(1).get("applicant").equals("2")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "非法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("1") && respondent.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("label", "法人组织");
                    map1.put("count", 0);
                    respondent.add(map1);
                }
                if (respondent.get(0).get("applicant").equals("2") && respondent.get(1).get("applicant").equals("3")) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label", "自然人");
                    map.put("count", 0);
                    respondent.add(map);
                }
            }
        }
        if (dataAll.size() == 0) {
            dataAll = getDefaultValuePeople();
        }

        dataResult.put("applicant", applicant);
        dataResult.put("respondent", respondent);
        dataResult.put("all", dataAll);
        return dataResult;
    }

    /**
     * 获取7天时间
     *
     * @return
     */
    private List<String> getDateSeven(String endTime) {
        List<String> dateList = new ArrayList<>();
        Date date = null;
        LocalDate now = null;

        if(endTime!=null&&!endTime.equals("")){
            now = LocalDate.parse(endTime);

            LocalDate localDate = LocalDate.parse(endTime);
            ZoneId zoneId = ZoneId.systemDefault();
            ZonedDateTime zonedDateTime = localDate.atStartOfDay(zoneId);
            date = Date.from(zonedDateTime.toInstant());
        }else {
            date = new Date();
            now = LocalDate.now();
        }
        int month = date.getMonth() + 1;//获取当前的月份
        int day = date.getDate();//获取当月听阿叔
        int lastDays = 0;//上个月的天数
        String firstDay = month + "-" + day;
        String secondDay = "";
        String threeDay = "";
        String fourDay = "";
        String fiveDay = "";
        String sixDay = "";
        String sevenDay = "";
        boolean flag = false;
        if (day - 1 > 0) {
            secondDay = month + "-" + (day - 1);
        } else {
            LocalDate minusMonths = now.minusMonths(1);
            lastDays = minusMonths.lengthOfMonth();//上个月天数
            month = month - 1;//上个月
            secondDay = month + "-" + (lastDays - Math.abs(day - 1));
            flag = true;
        }

        if (day - 2 > 0) {
            threeDay = month + "-" + (day - 2);
        } else {
            if (flag) {
                threeDay = month + "-" + (lastDays - Math.abs(day - 2));
            } else {
                LocalDate minusMonths = now.minusMonths(1);
                lastDays = minusMonths.lengthOfMonth();
                month = month - 1;//上个月
                threeDay = month + "-" + (lastDays - Math.abs(day - 2));
                flag = true;
            }
        }

        if (day - 3 > 0) {
            fourDay = month + "-" + (day - 3);
        } else {
            if (flag) {
                fourDay = month + "-" + (lastDays - Math.abs(day - 3));
            } else {
                LocalDate minusMonths = now.minusMonths(1);
                lastDays = minusMonths.lengthOfMonth();
                month = month - 1;//上个月
                fourDay = month + "-" + (lastDays - Math.abs(day - 3));
                flag = true;
            }
        }
        if (day - 4 > 0) {
            fiveDay = month + "-" + (day - 4);
        } else {
            if (flag) {
                fiveDay = month + "-" + (lastDays - Math.abs(day - 4));
            } else {
                LocalDate minusMonths = now.minusMonths(1);
                lastDays = minusMonths.lengthOfMonth();
                month = month - 1;//上个月
                fiveDay = month + "-" + (lastDays - Math.abs(day - 4));
                flag = true;
            }
        }
        if (day - 5 > 0) {
            sixDay = month + "-" + (day - 5);
        } else {
            if (flag) {
                sixDay = month + "-" + (lastDays - Math.abs(day - 5));
            } else {
                LocalDate minusMonths = now.minusMonths(1);
                lastDays = minusMonths.lengthOfMonth();
                month = month - 1;//上个月
                sixDay = month + "-" + (lastDays - Math.abs(day - 5));
                flag = true;
            }
        }
        if (day - 6 > 0) {
            sevenDay = month + "-" + (day - 6);
        } else {
            if (flag) {
                sevenDay = month + "-" + (lastDays - Math.abs(day - 6));
            } else {
                LocalDate minusMonths = now.minusMonths(1);
                lastDays = minusMonths.lengthOfMonth();
                month = month - 1;//上个月
                sevenDay = month + "-" + (lastDays - Math.abs(day - 6));
                flag = true;
            }
        }
        dateList.add(firstDay);
        dateList.add(secondDay);
        dateList.add(threeDay);
        dateList.add(fourDay);
        dateList.add(fiveDay);
        dateList.add(sixDay);
        dateList.add(sevenDay);
        return dateList;
    }

    @Override
    public Map<String, Long> disputeTrend(String endTime) {
        Map<String, Long> dataResult = null;
        Long userId = SecurityUtils.getUserId();//用户id
        if (userId == 1) {
            dataResult = getTrendByAdmin(endTime);
            return dataResult;
        }
        //1、区级综窗
        Long roleSynthesis = getRoleSynthesis(userId);
        if (roleSynthesis != null) {
            dataResult = getTrendBySynthesis(userId, endTime);
            return dataResult;
        }
        //2、乡镇综窗
        Long roleSynthesisTown = getRoleSynthesisTown(userId);
        if (roleSynthesisTown != null) {//乡镇综窗
            dataResult = getTrendBySynthesis(userId, endTime);
            return dataResult;
        }
        //3、专窗
        Long[] windowIds = indexDisputeEventMapper.getWindowIdByUserId(userId);
        if (windowIds!=null&&windowIds.length > 0) {
            dataResult = getTrendByWindows(windowIds, endTime);
            return dataResult;
        }
        //4、乡镇治理中心
        Long[] townShipByUserId = indexDisputeEventMapper.getTownShipByUserId(userId);
        if (townShipByUserId!=null&&townShipByUserId.length > 0) {
            dataResult = getTrendByTownShip(townShipByUserId, endTime);
            return dataResult;
        }
        //5、调解员
        dataResult = getTrendByMediator(userId, endTime);
        return dataResult;
    }

    //超管
    private Map<String, Long> getTrendByAdmin(String endTime) {
        //第一天 第二天 第三天 第四天 第五天 第六天 第七天
        //非纠纷
        String str = "";
        if (endTime.equals("")) {
            str = simpleDateFormatYMD.format(new Date());
        } else {
            str=endTime;
        }
        Map<String, Long> notTrend = indexDisputeEventMapper.getDisputeTrendNot(str);
        //一般纠纷
        Map<String, Long> ordTrend = indexDisputeEventMapper.getDisputeTrendOrd(str);
        //诉前纠纷
        Map<String, Long> preTrend = indexDisputeEventMapper.getDisputeTrendPre(str);

        List<String> dateList = getDateSeven(endTime);
        Map<String, Long> dataMap = new LinkedHashMap<>();

        if (notTrend == null || notTrend.size() == 0) {
            notTrend = new HashMap<>();
            notTrend.put("firstDay", 0l);
            notTrend.put("secondDay", 0l);
            notTrend.put("threeDay", 0l);
            notTrend.put("fourDay", 0l);
            notTrend.put("fiveDay", 0l);
            notTrend.put("sixDay", 0l);
            notTrend.put("sevenDay", 0l);
        }
        if (ordTrend == null || ordTrend.size() == 0) {
            ordTrend = new HashMap<>();
            ordTrend.put("firstDay", 0l);
            ordTrend.put("secondDay", 0l);
            ordTrend.put("threeDay", 0l);
            ordTrend.put("fourDay", 0l);
            ordTrend.put("fiveDay", 0l);
            ordTrend.put("sixDay", 0l);
            ordTrend.put("sevenDay", 0l);
        }
        if (preTrend == null || preTrend.size() == 0) {
            preTrend = new HashMap<>();
            preTrend.put("firstDay", 0l);
            preTrend.put("secondDay", 0l);
            preTrend.put("threeDay", 0l);
            preTrend.put("fourDay", 0l);
            preTrend.put("fiveDay", 0l);
            preTrend.put("sixDay", 0l);
            preTrend.put("sevenDay", 0l);
        }
        dataMap.put(dateList.get(6), notTrend.get("sevenDay") + ordTrend.get("sevenDay") + preTrend.get("sevenDay"));
        dataMap.put(dateList.get(5), notTrend.get("sixDay") + ordTrend.get("sixDay") + preTrend.get("sixDay"));
        dataMap.put(dateList.get(4), notTrend.get("fiveDay") + ordTrend.get("fiveDay") + preTrend.get("fiveDay"));
        dataMap.put(dateList.get(3), notTrend.get("fourDay") + ordTrend.get("fourDay") + preTrend.get("fourDay"));
        dataMap.put(dateList.get(2), notTrend.get("threeDay") + ordTrend.get("threeDay") + preTrend.get("threeDay"));
        dataMap.put(dateList.get(1), notTrend.get("secondDay") + ordTrend.get("secondDay") + preTrend.get("secondDay"));
        dataMap.put(dateList.get(0), notTrend.get("firstDay") + ordTrend.get("firstDay") + preTrend.get("firstDay"));
        return dataMap;
    }

    //综窗
    private Map<String, Long> getTrendBySynthesis(Long userId, String endTime) {
        //第一天 第二天 第三天 第四天 第五天 第六天 第七天
        String str = "";
        if (endTime.equals("")) {
            str = simpleDateFormatYMD.format(new Date());
        } else {
            str = endTime.split(" ")[0];
        }
        //非纠纷
        Map<String, Long> notTrend = indexDisputeEventMapper.getDisputeTrendNotSynthesis(userId, str);
        //一般纠纷
        Map<String, Long> ordTrend = indexDisputeEventMapper.getDisputeTrendOrdSynthesis(userId, str);
        //诉前纠纷
        Map<String, Long> preTrend = indexDisputeEventMapper.getDisputeTrendPreSynthesis(userId, str);

        List<String> dateList = getDateSeven(endTime);
        Map<String, Long> dataMap = new LinkedHashMap<>();

        if (notTrend == null || notTrend.size() == 0) {
            notTrend = new HashMap<>();
            notTrend.put("firstDay", 0l);
            notTrend.put("secondDay", 0l);
            notTrend.put("threeDay", 0l);
            notTrend.put("fourDay", 0l);
            notTrend.put("fiveDay", 0l);
            notTrend.put("sixDay", 0l);
            notTrend.put("sevenDay", 0l);
        }
        if (ordTrend == null || ordTrend.size() == 0) {
            ordTrend = new HashMap<>();
            ordTrend.put("firstDay", 0l);
            ordTrend.put("secondDay", 0l);
            ordTrend.put("threeDay", 0l);
            ordTrend.put("fourDay", 0l);
            ordTrend.put("fiveDay", 0l);
            ordTrend.put("sixDay", 0l);
            ordTrend.put("sevenDay", 0l);
        }
        if (preTrend == null || preTrend.size() == 0) {
            preTrend = new HashMap<>();
            preTrend.put("firstDay", 0l);
            preTrend.put("secondDay", 0l);
            preTrend.put("threeDay", 0l);
            preTrend.put("fourDay", 0l);
            preTrend.put("fiveDay", 0l);
            preTrend.put("sixDay", 0l);
            preTrend.put("sevenDay", 0l);
        }
        dataMap.put(dateList.get(6), notTrend.get("sevenDay") + ordTrend.get("sevenDay") + preTrend.get("sevenDay"));
        dataMap.put(dateList.get(5), notTrend.get("sixDay") + ordTrend.get("sixDay") + preTrend.get("sixDay"));
        dataMap.put(dateList.get(4), notTrend.get("fiveDay") + ordTrend.get("fiveDay") + preTrend.get("fiveDay"));
        dataMap.put(dateList.get(3), notTrend.get("fourDay") + ordTrend.get("fourDay") + preTrend.get("fourDay"));
        dataMap.put(dateList.get(2), notTrend.get("threeDay") + ordTrend.get("threeDay") + preTrend.get("threeDay"));
        dataMap.put(dateList.get(1), notTrend.get("secondDay") + ordTrend.get("secondDay") + preTrend.get("secondDay"));
        dataMap.put(dateList.get(0), notTrend.get("firstDay") + ordTrend.get("firstDay") + preTrend.get("firstDay"));
        return dataMap;
    }

    //专窗
    private Map<String, Long> getTrendByWindows(Long[] windows, String endTime) {
        //第一天 第二天 第三天 第四天 第五天 第六天 第七天
        String str = "";
        if (endTime.equals("")) {
            str = simpleDateFormatYMD.format(new Date());
        } else {
            str = endTime.split(" ")[0];
        }
        //非纠纷
        Map<String, Long> notTrend = indexDisputeEventMapper.getDisputeTrendNotWindows(windows, str);
        //一般纠纷
        Map<String, Long> ordTrend = indexDisputeEventMapper.getDisputeTrendOrdWindows(windows, str);
        //诉前纠纷
        Map<String, Long> preTrend = indexDisputeEventMapper.getDisputeTrendPreWindows(windows, str);

        List<String> dateList = getDateSeven(endTime);
        Map<String, Long> dataMap = new LinkedHashMap<>();

        if (notTrend == null || notTrend.size() == 0) {
            notTrend = new HashMap<>();
            notTrend.put("firstDay", 0l);
            notTrend.put("secondDay", 0l);
            notTrend.put("threeDay", 0l);
            notTrend.put("fourDay", 0l);
            notTrend.put("fiveDay", 0l);
            notTrend.put("sixDay", 0l);
            notTrend.put("sevenDay", 0l);
        }
        if (ordTrend == null || ordTrend.size() == 0) {
            ordTrend = new HashMap<>();
            ordTrend.put("firstDay", 0l);
            ordTrend.put("secondDay", 0l);
            ordTrend.put("threeDay", 0l);
            ordTrend.put("fourDay", 0l);
            ordTrend.put("fiveDay", 0l);
            ordTrend.put("sixDay", 0l);
            ordTrend.put("sevenDay", 0l);
        }
        if (preTrend == null || preTrend.size() == 0) {
            preTrend = new HashMap<>();
            preTrend.put("firstDay", 0l);
            preTrend.put("secondDay", 0l);
            preTrend.put("threeDay", 0l);
            preTrend.put("fourDay", 0l);
            preTrend.put("fiveDay", 0l);
            preTrend.put("sixDay", 0l);
            preTrend.put("sevenDay", 0l);
        }
        dataMap.put(dateList.get(6), notTrend.get("sevenDay") + ordTrend.get("sevenDay") + preTrend.get("sevenDay"));
        dataMap.put(dateList.get(5), notTrend.get("sixDay") + ordTrend.get("sixDay") + preTrend.get("sixDay"));
        dataMap.put(dateList.get(4), notTrend.get("fiveDay") + ordTrend.get("fiveDay") + preTrend.get("fiveDay"));
        dataMap.put(dateList.get(3), notTrend.get("fourDay") + ordTrend.get("fourDay") + preTrend.get("fourDay"));
        dataMap.put(dateList.get(2), notTrend.get("threeDay") + ordTrend.get("threeDay") + preTrend.get("threeDay"));
        dataMap.put(dateList.get(1), notTrend.get("secondDay") + ordTrend.get("secondDay") + preTrend.get("secondDay"));
        dataMap.put(dateList.get(0), notTrend.get("firstDay") + ordTrend.get("firstDay") + preTrend.get("firstDay"));
        return dataMap;
    }

    //乡镇治理中心
    private Map<String, Long> getTrendByTownShip(Long[] townShipIds, String endTime) {
        //第一天 第二天 第三天 第四天 第五天 第六天 第七天
        String str = "";
        if (endTime.equals("")) {
            str = simpleDateFormatYMD.format(new Date());
        } else {
            str = endTime.split(" ")[0];
        }
        //非纠纷
        Map<String, Long> notTrend = indexDisputeEventMapper.getDisputeTrendNotTownShip(townShipIds, str);
        //一般纠纷
        Map<String, Long> ordTrend = indexDisputeEventMapper.getDisputeTrendOrdTownShip(townShipIds, str);
        //诉前纠纷
        Map<String, Long> preTrend = indexDisputeEventMapper.getDisputeTrendPreTownShip(townShipIds, str);

        List<String> dateList = getDateSeven(endTime);
        Map<String, Long> dataMap = new LinkedHashMap<>();

        if (notTrend == null || notTrend.size() == 0) {
            notTrend = new HashMap<>();
            notTrend.put("firstDay", 0l);
            notTrend.put("secondDay", 0l);
            notTrend.put("threeDay", 0l);
            notTrend.put("fourDay", 0l);
            notTrend.put("fiveDay", 0l);
            notTrend.put("sixDay", 0l);
            notTrend.put("sevenDay", 0l);
        }
        if (ordTrend == null || ordTrend.size() == 0) {
            ordTrend = new HashMap<>();
            ordTrend.put("firstDay", 0l);
            ordTrend.put("secondDay", 0l);
            ordTrend.put("threeDay", 0l);
            ordTrend.put("fourDay", 0l);
            ordTrend.put("fiveDay", 0l);
            ordTrend.put("sixDay", 0l);
            ordTrend.put("sevenDay", 0l);
        }
        if (preTrend == null || preTrend.size() == 0) {
            preTrend = new HashMap<>();
            preTrend.put("firstDay", 0l);
            preTrend.put("secondDay", 0l);
            preTrend.put("threeDay", 0l);
            preTrend.put("fourDay", 0l);
            preTrend.put("fiveDay", 0l);
            preTrend.put("sixDay", 0l);
            preTrend.put("sevenDay", 0l);
        }
        dataMap.put(dateList.get(6), notTrend.get("sevenDay") + ordTrend.get("sevenDay") + preTrend.get("sevenDay"));
        dataMap.put(dateList.get(5), notTrend.get("sixDay") + ordTrend.get("sixDay") + preTrend.get("sixDay"));
        dataMap.put(dateList.get(4), notTrend.get("fiveDay") + ordTrend.get("fiveDay") + preTrend.get("fiveDay"));
        dataMap.put(dateList.get(3), notTrend.get("fourDay") + ordTrend.get("fourDay") + preTrend.get("fourDay"));
        dataMap.put(dateList.get(2), notTrend.get("threeDay") + ordTrend.get("threeDay") + preTrend.get("threeDay"));
        dataMap.put(dateList.get(1), notTrend.get("secondDay") + ordTrend.get("secondDay") + preTrend.get("secondDay"));
        dataMap.put(dateList.get(0), notTrend.get("firstDay") + ordTrend.get("firstDay") + preTrend.get("firstDay"));
        return dataMap;
    }

    //调解员
    private Map<String, Long> getTrendByMediator(Long userId, String endTime) {
        //第一天 第二天 第三天 第四天 第五天 第六天 第七天
        String str = "";
        if (endTime.equals("")) {
            str = simpleDateFormatYMD.format(new Date());
        } else {
            str = endTime.split(" ")[0];
        }
        //非纠纷
        Map<String, Long> notTrend = indexDisputeEventMapper.getDisputeTrendNotMediator(userId, str);
        //一般纠纷
        Map<String, Long> ordTrend = indexDisputeEventMapper.getDisputeTrendOrdMediator(userId, str);
        //诉前纠纷
        Map<String, Long> preTrend = indexDisputeEventMapper.getDisputeTrendPreMediator(userId, str);

        List<String> dateList = getDateSeven(endTime);
        Map<String, Long> dataMap = new LinkedHashMap<>();

        if (notTrend == null || notTrend.size() == 0) {
            notTrend = new HashMap<>();
            notTrend.put("firstDay", 0l);
            notTrend.put("secondDay", 0l);
            notTrend.put("threeDay", 0l);
            notTrend.put("fourDay", 0l);
            notTrend.put("fiveDay", 0l);
            notTrend.put("sixDay", 0l);
            notTrend.put("sevenDay", 0l);
        }
        if (ordTrend == null || ordTrend.size() == 0) {
            ordTrend = new HashMap<>();
            ordTrend.put("firstDay", 0l);
            ordTrend.put("secondDay", 0l);
            ordTrend.put("threeDay", 0l);
            ordTrend.put("fourDay", 0l);
            ordTrend.put("fiveDay", 0l);
            ordTrend.put("sixDay", 0l);
            ordTrend.put("sevenDay", 0l);
        }
        if (preTrend == null || preTrend.size() == 0) {
            preTrend = new HashMap<>();
            preTrend.put("firstDay", 0l);
            preTrend.put("secondDay", 0l);
            preTrend.put("threeDay", 0l);
            preTrend.put("fourDay", 0l);
            preTrend.put("fiveDay", 0l);
            preTrend.put("sixDay", 0l);
            preTrend.put("sevenDay", 0l);
        }
        dataMap.put(dateList.get(6), notTrend.get("sevenDay") + ordTrend.get("sevenDay") + preTrend.get("sevenDay"));
        dataMap.put(dateList.get(5), notTrend.get("sixDay") + ordTrend.get("sixDay") + preTrend.get("sixDay"));
        dataMap.put(dateList.get(4), notTrend.get("fiveDay") + ordTrend.get("fiveDay") + preTrend.get("fiveDay"));
        dataMap.put(dateList.get(3), notTrend.get("fourDay") + ordTrend.get("fourDay") + preTrend.get("fourDay"));
        dataMap.put(dateList.get(2), notTrend.get("threeDay") + ordTrend.get("threeDay") + preTrend.get("threeDay"));
        dataMap.put(dateList.get(1), notTrend.get("secondDay") + ordTrend.get("secondDay") + preTrend.get("secondDay"));
        dataMap.put(dateList.get(0), notTrend.get("firstDay") + ordTrend.get("firstDay") + preTrend.get("firstDay"));
        return dataMap;
    }

    /**
     * 综窗
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<Object> disputeSynthesis(String startTime, String endTime) {
        List<Object> dataResult = new ArrayList<>();

        Long userId = SecurityUtils.getUserId();
        if (userId == 1) {
            userId = null;
        }
        //情况汇总
        Map<String, Long> synthesisWork = indexDisputeEventMapper.getDisputeSynthesisWork(userId, startTime, endTime);
        //状态统计
        Map<String, Long> synthesisStatus = indexDisputeEventMapper.getDisputeSynthesisStatus(userId, startTime, endTime);

        //纠纷类型 非纠纷
        List<Map<String, Object>> mediatorTypeNot = indexDisputeEventMapper.getDisputeSynthesisTypeNot(userId, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> mediatorTypeOrd = indexDisputeEventMapper.getDisputeSynthesisTypeOrd(userId, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> mediatorTypePre = indexDisputeEventMapper.getDisputeSynthesisTypePre(userId, startTime, endTime);

        //纠纷地区
        List<Map<String, Object>> mediatorAreaNot = indexDisputeEventMapper.getDisputeSynthesisAreaNot(userId, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> mediatorAreaOrd = indexDisputeEventMapper.getDisputeSynthesisAreaOrd(userId, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> mediatorAreaPre = indexDisputeEventMapper.getDisputeSynthesisAreaPre(userId, startTime, endTime);

        List<Map<String, Object>> notArea = mediatorAreaNot.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> ordArea = mediatorAreaOrd.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> preArea = mediatorAreaPre.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        Long preId = null;
        if (notArea.size() > 0) {
            preId = (Long) notArea.get(0).get("preId");
        }
        if (ordArea.size() > 0) {
            preId = (Long) ordArea.get(0).get("preId");
        }
        if (preArea.size() > 0) {
            preId = (Long) preArea.get(0).get("preId");
        }
        List<Map<String, Object>> areaVillage = null;
        if (preId != null) {
            areaVillage = getAreaVillage(preId);
        } else {
            preId = 1l;
            areaVillage = getAreaVillage(preId);
        }

        List<Object> dataArea = new ArrayList();
        long count = 0;
        for (Map<String, Object> areaMap : areaVillage) {
            count = 0;
            Map<String, Object> objectMap = new HashMap<>();
            List<Map<String, Object>> notList = notArea.stream()
                    .filter(map -> map.get("area").equals(areaMap.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> ordList = ordArea.stream()
                    .filter(map -> map.get("area").equals(areaMap.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> preList = preArea.stream()
                    .filter(map -> map.get("area").equals(areaMap.get("villageName")))
                    .collect(Collectors.toList());
            for (Map<String, Object> map : notList) {
                count += (Long) map.get("count");
            }
            for (Map<String, Object> map : ordList) {
                count += (Long) map.get("count");
            }
            for (Map<String, Object> map : preList) {
                count += (Long) map.get("count");
            }

            objectMap.put("count", count);
            objectMap.put("area", areaMap);
            dataArea.add(objectMap);
        }


        Map<String, Object> statusMap = new HashMap<>();
        statusMap.put("box",
                synthesisStatus.get("notBox") + synthesisStatus.get("ordBox") + synthesisStatus.get("preBox"));
        statusMap.put("assigned1",
                synthesisStatus.get("notAssigned1") + synthesisStatus.get("ordAssigned1") + synthesisStatus.get("preAssigned1"));
        statusMap.put("assigned2",
                synthesisStatus.get("notAssigned2") + synthesisStatus.get("ordAssigned2") + synthesisStatus.get("preAssigned2"));

        Map<String, Object> typeMap = new HashMap<>();
        if (mediatorTypeNot.size() == 0 || mediatorTypeNot.get(0).size() == 1) {
            mediatorTypeNot = getDefaultValueNot();
        }
        if (mediatorTypeOrd.size() == 0 || mediatorTypeOrd.get(0).size() == 1) {
            mediatorTypeOrd = getDefaultValue();
        }
        if (mediatorTypePre.size() == 0 || mediatorTypePre.get(0).size() == 1) {
            mediatorTypePre = getDefaultValuePre();
        }

        typeMap.put("notType", mediatorTypeNot);
        typeMap.put("ordType", mediatorTypeOrd);
        typeMap.put("preType", mediatorTypePre);

        dataResult.add(synthesisWork);
        dataResult.add(statusMap);
        dataResult.add(typeMap);
        dataResult.add(dataArea);
        return dataResult;
    }

    /**
     * 专窗
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<Object> disputeWindow(String startTime, String endTime) {
        List<Object> dataResult = new ArrayList<>();
        //获取当前所在的窗口
        Long userId = SecurityUtils.getUserId();
        Long[] windowIds = null;
        if (userId == 1) {
            userId = null;
            windowIds = indexDisputeEventMapper.getWindowIdAll();
            dataResult.addAll(getWindow(windowIds,startTime,endTime));
            return dataResult;
        }
        //区级专窗
        Long roleQujizhuanchuang = indexDisputeEventMapper.getWindowRoleQujizhuanchuang(userId);
        if (roleQujizhuanchuang != null) {
            windowIds = indexDisputeEventMapper.getWindowIdByUserId(userId);
            dataResult.addAll(getWindow(windowIds,startTime,endTime));
            return dataResult;
        }
        //乡镇治理中心
        Long[] townShipByUserId = indexDisputeEventMapper.getTownShipByUserId(userId);
        dataResult.addAll(getTownShip(townShipByUserId,startTime,endTime));
        return dataResult;
    }

    //专窗
    private List<Object> getWindow(Long[] windowIds,String startTime,String endTime) {
        List<Object> dataResult = new ArrayList<>();
        if (windowIds != null && windowIds.length == 0) {
            windowIds = new Long[]{999999999999999L};
        }
        //情况汇总
        Map<String, Long> windowWork = indexDisputeEventMapper.getDisputeWindowWork(windowIds, startTime, endTime);
        //状态统计  待受理
        Map<String, Long> windowStatus = indexDisputeEventMapper.getDisputeWindowStatus(windowIds, startTime, endTime);
        //纠纷类型 非纠纷
        List<Map<String, Object>> mediatorTypeNot = indexDisputeEventMapper.getDisputeWindowTypeNot(windowIds, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> mediatorTypeOrd = indexDisputeEventMapper.getDisputeWindowTypeOrd(windowIds, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> mediatorTypePre = indexDisputeEventMapper.getDisputeWindowTypePre(windowIds, startTime, endTime);

        //纠纷地区
        List<Map<String, Object>> mediatorAreaNot = indexDisputeEventMapper.getDisputeWindowAreaNot(windowIds, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> mediatorAreaOrd = indexDisputeEventMapper.getDisputeWindowAreaOrd(windowIds, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> mediatorAreaPre = indexDisputeEventMapper.getDisputeWindowAreaPre(windowIds, startTime, endTime);

        List<Map<String, Object>> notArea = mediatorAreaNot.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> ordArea = mediatorAreaOrd.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> preArea = mediatorAreaPre.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        Long preId = null;
        if (notArea.size() > 0) {
            preId = (Long) notArea.get(0).get("preId");
        }
        if (ordArea.size() > 0) {
            preId = (Long) ordArea.get(0).get("preId");
        }
        if (preArea.size() > 0) {
            preId = (Long) preArea.get(0).get("preId");
        }
        List<Map<String, Object>> areaVillage = null;
        if (preId != null) {
            areaVillage = getAreaVillage(preId);
        } else {
            preId = 1l;
            areaVillage = getAreaVillage(preId);
        }

        List<Object> dataArea = new ArrayList();
        long count = 0;
        for (Map<String, Object> area : areaVillage) {
            count=0;
            Map<String, Object> objectMap = new HashMap<>();
            List<Map<String, Object>> notList = notArea.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> ordList = ordArea.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> preList = preArea.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            for (Map<String, Object> map : notList) {
                count += (Long) map.get("count");
            }
            for (Map<String, Object> map : ordList) {
                count += (Long) map.get("count");
            }
            for (Map<String, Object> map : preList) {
                count += (Long) map.get("count");
            }

            objectMap.put("count", count);
            objectMap.put("area", area);
            dataArea.add(objectMap);
        }

        Map<String, Object> statusMap = new HashMap<>();
        statusMap.put("accepted1",
                windowStatus.get("notAccepted1") + windowStatus.get("ordAccepted1") + windowStatus.get("preAccepted1"));
        statusMap.put("accepted2",
                windowStatus.get("notAccepted2") + windowStatus.get("ordAccepted2") + windowStatus.get("preAccepted2"));
        statusMap.put("prePending1",
                windowStatus.get("notPending1") + windowStatus.get("ordPending1") + windowStatus.get("prePending1"));
        statusMap.put("prePending2",
                windowStatus.get("notPending2") + windowStatus.get("ordPending2") + windowStatus.get("prePending2"));

        Map<String, Object> typeMap = new HashMap<>();
        if (mediatorTypeNot.size() == 0 || mediatorTypeNot.get(0).size() == 1) {
            mediatorTypeNot = getDefaultValueNot();
        }
        if (mediatorTypeOrd.size() == 0 || mediatorTypeOrd.get(0).size() == 1) {
            mediatorTypeOrd = getDefaultValue();
        }
        if (mediatorTypePre.size() == 0 || mediatorTypePre.get(0).size() == 1) {
            mediatorTypePre = getDefaultValuePre();
        }
        typeMap.put("notType", mediatorTypeNot);
        typeMap.put("ordType", mediatorTypeOrd);
        typeMap.put("preType", mediatorTypePre);
        dataResult.add(windowWork);
        dataResult.add(statusMap);
        dataResult.add(typeMap);
        dataResult.add(dataArea);
        return dataResult;
    }
    //治理中心
    private List<Object> getTownShip(Long[] townShipIds,String startTime,String endTime) {
        List<Object> dataResult = new ArrayList<>();
        if (townShipIds != null && townShipIds.length == 0) {
            townShipIds = new Long[]{999999999999999L};
        }
        //情况汇总
        Map<String, Long> windowWork = indexDisputeEventMapper.getDisputeWindowTownShip(townShipIds, startTime, endTime);
        //状态统计  待受理
        Map<String, Long> windowStatus = indexDisputeEventMapper.getDisputeTownShipStatus(townShipIds, startTime, endTime);
        //纠纷类型 非纠纷
        List<Map<String, Object>> mediatorTypeNot = indexDisputeEventMapper.getDisputeTownShipTypeNot(townShipIds, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> mediatorTypeOrd = indexDisputeEventMapper.getDisputeTownShipTypeOrd(townShipIds, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> mediatorTypePre = indexDisputeEventMapper.getDisputeTownShipTypePre(townShipIds, startTime, endTime);

        //纠纷地区
        List<Map<String, Object>> mediatorAreaNot = indexDisputeEventMapper.getDisputeTownShipAreaNot(townShipIds, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> mediatorAreaOrd = indexDisputeEventMapper.getDisputeTownShipAreaOrd(townShipIds, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> mediatorAreaPre = indexDisputeEventMapper.getDisputeTownShipAreaPre(townShipIds, startTime, endTime);

        List<Map<String, Object>> notArea = mediatorAreaNot.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> ordArea = mediatorAreaOrd.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> preArea = mediatorAreaPre.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        Long preId = null;
        if (notArea.size() > 0) {
            preId = (Long) notArea.get(0).get("preId");
        }
        if (ordArea.size() > 0) {
            preId = (Long) ordArea.get(0).get("preId");
        }
        if (preArea.size() > 0) {
            preId = (Long) preArea.get(0).get("preId");
        }
        List<Map<String, Object>> areaVillage = null;
        if (preId != null) {
            areaVillage = getAreaVillage(preId);
        } else {
            preId = 1l;
            areaVillage = getAreaVillage(preId);
        }

        List<Object> dataArea = new ArrayList();
        long count = 0;
        for (Map<String, Object> area : areaVillage) {
            Map<String, Object> objectMap = new HashMap<>();
            List<Map<String, Object>> notList = notArea.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> ordList = ordArea.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> preList = preArea.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            for (Map<String, Object> map : notList) {
                count += (Long) map.get("count");
            }
            for (Map<String, Object> map : ordList) {
                count += (Long) map.get("count");
            }
            for (Map<String, Object> map : preList) {
                count += (Long) map.get("count");
            }

            objectMap.put("count", count);
            objectMap.put("area", area);
            dataArea.add(objectMap);
        }

        Map<String, Object> statusMap = new HashMap<>();
        statusMap.put("accepted1",
                windowStatus.get("notAccepted1") + windowStatus.get("ordAccepted1") + windowStatus.get("preAccepted1"));
        statusMap.put("accepted2",
                windowStatus.get("notAccepted2") + windowStatus.get("ordAccepted2") + windowStatus.get("preAccepted2"));
        statusMap.put("prePending1",
                windowStatus.get("notPending1") + windowStatus.get("ordPending1") + windowStatus.get("prePending1"));
        statusMap.put("prePending2",
                windowStatus.get("notPending2") + windowStatus.get("ordPending2") + windowStatus.get("prePending2"));

        Map<String, Object> typeMap = new HashMap<>();
        if (mediatorTypeNot.size() == 0 || mediatorTypeNot.get(0).size() == 1) {
            mediatorTypeNot = getDefaultValueNot();
        }
        if (mediatorTypeOrd.size() == 0 || mediatorTypeOrd.get(0).size() == 1) {
            mediatorTypeOrd = getDefaultValue();
        }
        if (mediatorTypePre.size() == 0 || mediatorTypePre.get(0).size() == 1) {
            mediatorTypePre = getDefaultValuePre();
        }
        typeMap.put("notType", mediatorTypeNot);
        typeMap.put("ordType", mediatorTypeOrd);
        typeMap.put("preType", mediatorTypePre);
        dataResult.add(windowWork);
        dataResult.add(statusMap);
        dataResult.add(typeMap);
        dataResult.add(dataArea);
        return dataResult;
    }
    /**
     * 调解员
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<Object> disputeMediator(String startTime, String endTime) {
        List<Object> dataResult = new ArrayList<>();
        Long userId = SecurityUtils.getUserId();
        if (userId == 1) {
            userId = null;
        }
        //调解员 情况总览
        Map<String, Long> mediatorMap = indexDisputeEventMapper.getDisputeByMediator(userId, startTime, endTime);
        //状态统计 待调解 待结案
        Map<String, Long> mediatorStatusMap = indexDisputeEventMapper.getDisputeByMediatorStatus(userId, startTime, endTime);

        //纠纷类型统计 非纠纷
        List<Map<String, Object>> mediatorTypeNot = indexDisputeEventMapper.getDisputeByMediatorTypeNot(userId, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> mediatorTypeOrd = indexDisputeEventMapper.getDisputeByMediatorTypeOrd(userId, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> mediatorTypePre = indexDisputeEventMapper.getDisputeByMediatorTypePre(userId, startTime, endTime);

        //纠纷类型地区 非纠纷
        List<Map<String, Object>> mediatorAreaNot = indexDisputeEventMapper.getDisputeByMediatorAreaNot(userId, startTime, endTime);
        //一般纠纷
        List<Map<String, Object>> mediatorAreaOrd = indexDisputeEventMapper.getDisputeByMediatorAreaOrd(userId, startTime, endTime);
        //诉前纠纷
        List<Map<String, Object>> mediatorAreaPre = indexDisputeEventMapper.getDisputeByMediatorAreaPre(userId, startTime, endTime);

        List<Map<String, Object>> notArea = mediatorAreaNot.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> ordArea = mediatorAreaOrd.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());

        List<Map<String, Object>> preArea = mediatorAreaPre.stream()
                .filter(map -> map.get("preId") != null)
                .filter(map -> map.get("areaType") != null)
                .filter(map -> map.get("area") != null)
                .filter(map -> map.get("type") != null)
                .collect(Collectors.toList());
        Long preId = null;
        if (notArea.size() > 0) {
            preId = (Long) notArea.get(0).get("preId");
        }
        if (ordArea.size() > 0) {
            preId = (Long) ordArea.get(0).get("preId");
        }
        if (preArea.size() > 0) {
            preId = (Long) preArea.get(0).get("preId");
        }
        List<Map<String, Object>> areaVillage = null;
        if (preId != null) {
            areaVillage = getAreaVillage(preId);
        } else {
            preId = 1l;
            areaVillage = getAreaVillage(preId);
        }

        List<Object> dataArea = new ArrayList();
        long count = 0;
        for (Map<String, Object> area : areaVillage) {
            count = 0;
            Map<String, Object> objectMap = new HashMap<>();
            List<Map<String, Object>> notList = notArea.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> ordList = ordArea.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> preList = preArea.stream()
                    .filter(map -> map.get("area").equals(area.get("villageName")))
                    .collect(Collectors.toList());
            for (Map<String, Object> map : notList) {
                count += (Long) map.get("count");
            }
            for (Map<String, Object> map : ordList) {
                count += (Long) map.get("count");
            }
            for (Map<String, Object> map : preList) {
                count += (Long) map.get("count");
            }
            objectMap.put("count", count);
            objectMap.put("area", area);
            dataArea.add(objectMap);
        }

        Map<String, Object> typeMap = new HashMap<>();
        if (mediatorTypeNot.size() == 0 || mediatorTypeNot.get(0).size() == 1) {
            mediatorTypeNot = getDefaultValueNot();
        }
        if (mediatorTypeOrd.size() == 0 || mediatorTypeOrd.get(0).size() == 1) {
            mediatorTypeOrd = getDefaultValue();
        }
        if (mediatorTypePre.size() == 0 || mediatorTypePre.get(0).size() == 1) {
            mediatorTypePre = getDefaultValuePre();
        }

        typeMap.put("notType", mediatorTypeNot);
        typeMap.put("ordType", mediatorTypeOrd);
        typeMap.put("preType", mediatorTypePre);
        Map<String, Object> statusMap = new HashMap<>();
        statusMap.put("mediated1",
                mediatorStatusMap.get("ordMediated1") + mediatorStatusMap.get("preMediated1"));
        statusMap.put("mediated2",
                mediatorStatusMap.get("ordMediated2") + mediatorStatusMap.get("preMediated2"));
        statusMap.put("prePending1",
                mediatorStatusMap.get("ordPending1") + mediatorStatusMap.get("prePending1"));
        statusMap.put("prePending2",
                mediatorStatusMap.get("ordPending2") + mediatorStatusMap.get("prePending2"));

        dataResult.add(mediatorMap);
        dataResult.add(statusMap);
        dataResult.add(typeMap);
        dataResult.add(dataArea);
        return dataResult;
    }

    @Override
    public List<Object> getAllArea() {
        //获取镇、村、户
        List<Map<String, Object>> areaLevelTown = getAreaTown();
        List<Map<String, Object>> areaAll = indexDisputeEventMapper.getAreaAll();
        List<Object> dataResult = new ArrayList<>();
        areaLevelTown.forEach(townMap -> {
            //过滤镇
            Map<String, Object> objectHashMap = new HashMap<>();

            List<Object> list = new ArrayList<>();
            List<Map<String, Object>> villageList = areaAll.stream()
                    .filter(map -> map.get("townName").equals(townMap.get("townName")))
                    .collect(Collectors.toList());
            List<Map<String, Object>> areaVillage = getAreaVillage((Long) townMap.get("townId"));
            areaVillage.forEach(village -> {
                Map<String, Object> hashMap = new HashMap<>();
                List<Map<String, Object>> houseList = villageList.stream()
                        .filter(map -> map.get("villageName").equals(village.get("villageName")))
                        .collect(Collectors.toList());
                List<Object> list1 = new ArrayList<>();
                houseList.forEach(house -> {
                    if (house.get("houseId") != null && house.get("houseName") != null) {
                        Map<String, Object> h = new HashMap<>();
                        h.put("value", house.get("houseId"));
                        h.put("label", house.get("houseName"));
                        list1.add(h);
                    }
                });
                if (list1.size() > 0) {
                    hashMap.put("children", list1);
                } else {
                    hashMap.put("children", null);
                }
                hashMap.put("label", village.get("villageName"));
                hashMap.put("value", village.get("villageId"));
                list.add(hashMap);
            });
            objectHashMap.put("value", townMap.get("townId"));
            objectHashMap.put("label", townMap.get("townName"));
            if (list.size() > 0) {
                objectHashMap.put("children", list);
            } else {
                objectHashMap.put("children", null);
            }
            dataResult.add(objectHashMap);
        });

        List<Object> data = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("value", areaAll.get(0).get("districtId"));
        map.put("label", areaAll.get(0).get("districtName"));
        map.put("children", dataResult);
        data.add(map);
        return data;
    }

    /**
     * 获取地址集合
     *
     * @return
     */
    public List<Map<String, Object>> getAreaTown() {
        return indexDisputeEventMapper.getAreaTown();
    }

    /**
     * @param id 父级id
     * @return
     */
    public List<Map<String, Object>> getAreaVillage(Long id) {
        return indexDisputeEventMapper.getAreaVillage(id);
    }

    public List<Map<String, Object>> getAreaGrid(Long id) {
        return indexDisputeEventMapper.getAreaHouse(id);
    }

    //时间筛选
    private QueryTimeVo getTime(String query) {
        QueryTimeVo queryTimeVo = new QueryTimeVo();
        Calendar d = Calendar.getInstance();
        Date now = new Date();
        switch (query) {
            case "DAY":
//                d.setTime(now);
//                d.add(Calendar.DATE, -1);
//                queryTimeVo.setStartTime(simpleDateFormat.format(d.getTime()));
                queryTimeVo.setEndTime(simpleDateFormat.format(now));
                now.setSeconds(0);
                now.setMinutes(0);
                now.setHours(0);
                queryTimeVo.setStartTime(simpleDateFormat.format(now));
                break;
            case "MONTH":
                d.setTime(now);
                d.add(Calendar.MONTH, -1);
                queryTimeVo.setStartTime(simpleDateFormat.format(d.getTime()));
                queryTimeVo.setEndTime(simpleDateFormat.format(now));
                break;
            case "YEAR":
                d.setTime(now);
                d.add(Calendar.YEAR, -1);
                queryTimeVo.setStartTime(simpleDateFormat.format(d.getTime()));
                queryTimeVo.setEndTime(simpleDateFormat.format(now));
                break;
            case "ALL":
                queryTimeVo.setStartTime("");
                queryTimeVo.setEndTime("");
                break;
        }
        return queryTimeVo;
    }

    /**
     * 获取申请类别标题
     *
     * @param type
     * @return
     */
    private String getDisputeLabel(String type) {
        String label = "";
        switch (type) {
            case "1":
                label = "自然人";
                break;
            case "2":
                label = "法人组织";
                break;
            case "3":
                label = "非法人组织";
                break;
        }
        return label;
    }

    /**
     * 获取默认的地区类型 诉前、非纠纷、一般纠纷
     *
     * @return
     */
    private List<Map<String, Object>> getDefaultValuePreArea() {
        List<Map<String, Object>> list = new ArrayList<>();
        List<String> disputeNames = indexDisputeEventMapper.getDisputeTypePreName();
        disputeNames.forEach(disputeName -> {
            Map<String, Object> map = new HashMap<>();
            map.put("disputeName", disputeName);
            map.put("count", 0);
            list.add(map);
        });
        return list;
    }

    private List<Map<String, Object>> getDefaultValueNotArea() {
        List<Map<String, Object>> list = new ArrayList<>();
        List<String> disputeNames = indexDisputeEventMapper.getDisputeTypeNotName();
        disputeNames.forEach(disputeName -> {
            Map<String, Object> map = new HashMap<>();
            map.put("type", disputeName);
            map.put("count", 0);
            list.add(map);
        });
        return list;
    }

    private List<Map<String, Object>> getDefaultValueOrdArea() {
        List<Map<String, Object>> list = new ArrayList<>();
        List<String> disputeNames = indexDisputeEventMapper.getDisputeTypeOrdName();
        disputeNames.forEach(disputeName -> {
            Map<String, Object> map = new HashMap<>();
            map.put("type", disputeName);
            map.put("count", 0);
            list.add(map);
        });
        return list;
    }

    private List<Object> getDefaultValueArea() {
        List<Object> dataResult = new ArrayList<>();
        long preId = 1l;
        List<Map<String, Object>> areaVillage = getAreaVillage(preId);
        for (Map<String, Object> area : areaVillage) {
            Map<String, Object> objectMap = new HashMap<>();
            List<Object> dataList = new ArrayList<>();

            List<Map<String, Object>> defaultValue = getDefaultValueOrdArea();
            List<Map<String, Object>> defaultValueNot = getDefaultValueNotArea();
            List<Map<String, Object>> defaultValuePre = getDefaultValuePreArea();

            defaultValue.forEach(ord -> {
                ord.put("area", area.get("villageName"));
            });
            defaultValueNot.forEach(not -> {
                not.put("area", area.get("villageName"));
            });
            defaultValuePre.forEach(pre -> {
                pre.put("area", area.get("villageName"));
            });
            dataList.addAll(defaultValuePre);
            dataList.addAll(defaultValueNot);
            dataList.addAll(defaultValue);

            objectMap.put("data", dataList);
            objectMap.put("area", area);
            dataResult.add(objectMap);
        }
        return dataResult;
    }

    //纠纷类型默认值
    private List<Map<String, Object>> getDefaultValue() {
        List<Map<String, Object>> list = new ArrayList<>();
        List<String> disputeNames = indexDisputeEventMapper.getDisputeTypeOrdName();
        disputeNames.forEach(disputeName -> {
            Map<String, Object> map = new HashMap<>();
            map.put("disputeName", disputeName);
            map.put("count", 0);
            list.add(map);
        });
        return list;
    }

    private List<Map<String, Object>> getDefaultValuePre() {
        List<Map<String, Object>> list = new ArrayList<>();
        List<String> disputeNames = indexDisputeEventMapper.getDisputeTypePreName();
        disputeNames.forEach(disputeName -> {
            Map<String, Object> map = new HashMap<>();
            map.put("disputeName", disputeName);
            map.put("count", 0);
            list.add(map);
        });
        return list;
    }

    private List<Map<String, Object>> getDefaultValueNot() {
        List<Map<String, Object>> list = new ArrayList<>();
        List<String> disputeNames = indexDisputeEventMapper.getDisputeTypeNotName();
        disputeNames.forEach(disputeName -> {
            Map<String, Object> map = new HashMap<>();
            map.put("disputeName", disputeName);
            map.put("count", 0);
            list.add(map);
        });
        return list;
    }

    private List<Map<String, Object>> getDefaultValuePeople() {
        List<Map<String, Object>> all = new ArrayList<>();
        Map<String, Object> m1 = new HashMap<>();
        m1.put("label", "自然人");
        m1.put("count", "0");
        Map<String, Object> m2 = new HashMap<>();
        m2.put("label", "法人组织");
        m2.put("count", "0");

        Map<String, Object> m3 = new HashMap<>();
        m3.put("label", "法人组织");
        m3.put("count", "0");
        all.add(m1);
        all.add(m2);
        all.add(m3);
        return all;
    }

    //接待大屏默认值
    private List<Map<String, Object>> getDefaultValueOrdReception() {
        List<Map<String, Object>> list = new ArrayList<>();
        List<String> disputeNames = indexDisputeEventMapper.getDisputeTypeOrdName();
        disputeNames.forEach(disputeName -> {
            Map<String, Object> map = new HashMap<>();
            map.put("disputeName", disputeName);
            map.put("count", 0);
            map.put("total", 0);
            map.put("percentage", 0.0+"%");
            list.add(map);
        });
        return list;
    }

    private List<Map<String, Object>> getDefaultValuePreReception() {
        List<Map<String, Object>> list = new ArrayList<>();
        List<String> disputeNames = indexDisputeEventMapper.getDisputeTypePreName();
        disputeNames.forEach(disputeName -> {
            Map<String, Object> map = new HashMap<>();
            map.put("disputeName", disputeName);
            map.put("count", 0);
            map.put("total", 0);
            map.put("percentage", 0.0+"%");
            list.add(map);
        });
        return list;
    }

    private List<Map<String, Object>> getDefaultValueNotReception() {
        List<Map<String, Object>> list = new ArrayList<>();
        List<String> disputeNames = indexDisputeEventMapper.getDisputeTypeNotName();
        disputeNames.forEach(disputeName -> {
            Map<String, Object> map = new HashMap<>();
            map.put("windowName", disputeName);
            map.put("count", 0);
            map.put("total", 0);
            map.put("percentage", 0.0+"%");
            list.add(map);
        });
        return list;
    }
}
